<?php if (!defined('BASEPATH'))exit('No direct script access allowed');

class Ajax extends MY_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('bbs_account_model');
        $this->load->model('bbs_detail_model');
        $this->load->model('bbs_user_model');
        $this->load->model('bbs_article_model');
        $this->load->model('finance_list_model');
        $this->load->model('video_model');
        $this->load->model('account_model');
        $this->load->model('users_log_model');
        $this->load->model('task_model');
    }
    //加载任务列表
    function ajax_fetch_task(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $type = isset($_REQUEST['Type']) ? trim($_REQUEST['Type']) : "hot";
            $key = isset($_REQUEST['Key']) ? trim($_REQUEST['Key']) : "";
            $value = isset($_REQUEST['Value']) ? trim($_REQUEST['Value']) : "";
            $records_per_page = 12;
            //这块搜索暂时去掉
//            if($type == "act"){
//                $where = "w.tags_name like '%溜溜活动%' and w.status = 1 and w.is_show = 1 order by w.id desc";
//            }else{
//                if($key == "tag"){//标签搜索
//                    $tag = $this->db->select("id,name")->from("bbs_wenda_tags")->where(array("id"=>$value))->order_by("id desc")->get()->row_array();
//                    $tag_name = $tag['name'];
//                    if($type == "hot"){
//                        $where = "w.tags_name like '%$tag_name%' and w.hot = 1 and w.status = 1 and w.is_show = 1 order by w.sort desc,w.id desc";
//                    }elseif($type == "lasest"){
//                        $where = "w.tags_name like '%$tag_name%' and w.status = 1 and w.is_show = 1 order by w.id desc";
//                    }else{
//                        $where = "w.tags_name like '%$tag_name%' and w.status = 1 and w.is_show = 1 and w.answernum = 0 order by w.id desc";
//                    }
//
//                }elseif($key == "kw"){//标题关键字搜索
//                    if($type == "all"){
//                        $where = "(w.title like '%$value%' or w.tags_name like '%$value%') and w.status = 1 and w.is_show = 1 order by w.sort desc,w.id desc";
//                    }elseif($type == "lasest"){
//                        $where = "(w.title like '%$value%' or w.tags_name like '%$value%') and w.status = 1 and w.is_show = 1 order by w.id desc";
//                    }else{
//                        $where = "(w.title like '%$value%' or w.tags_name like '%$value%') and w.status = 1 and w.is_show = 1 and w.answernum = 0 order by w.id desc";
//                    }
//                }else{//默认搜索
//                    if($type == "hot"){
//                        $where = "w.hot = 1 and w.status = 1 and w.is_show = 1 order by w.sort desc,w.id desc";
//                    }elseif($type == "lasest"){
//                        $where = "w.status = 1 and w.is_show = 1 order by w.id desc";
//                    }else{
//                        $where = "w.status = 1 and w.is_show = 1 and w.answernum = 0 order by w.id desc";
//                    }
//                }
//            }

            $sqlCount = "select * from tan_task  where is_delete=0";
            $sqlList = "select t.*,u.username,ui.head_img,ui.nickname,(select count(*) from tan_subtasks st where st.tid=t.tid) as snum from tan_task t 
                left join tan_users u on t.uid=u.user_id left join tan_users_info ui on ui.user_id=u.user_id where t.is_delete=0 order by add_time desc limit ".($pageIndex * $records_per_page).",$records_per_page";//构造查询结果记录;
            $totalCount = $this->db->query($sqlCount)->num_rows();
            $list = $this->db->query($sqlList)->result_array();
            $html = $this->set_task_str($type,$value,$list);
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $html,
                    "goto" => true,
                    "totalPage" => ceil($totalCount/$records_per_page)
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }
    //加载首页文章
    function ajax_fetch_arts(){
        if($_POST){
            
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $type = isset($_REQUEST['Type']) ? trim($_REQUEST['Type']) : "cat";
            $value = isset($_REQUEST['Value']) ? trim($_REQUEST['Value']) : "hot";
            $records_per_page = 12;
            $where = '';
            if($type == "cat"){//类型搜索
                if($value == "hot"){//热门
                    $where .= "a.hot = 1 and a.status = 1 and a.show = 1 order by a.sort desc";
                }elseif($value == "latest"){//最近
                    $where .= " a.status = 1 and a.show = 1  order by a.id desc";
                }else{//板块分类
                    $cat_id = $value;
                    $where .= "a.cat_id = $cat_id and a.status = 1 and a.show = 1  order by a.sort desc,a.id desc";
                }
                
            }elseif($type == "kw"){//关键词搜索
                $where .= "(a.title like '%$value%' or a.tags_name like '%$value%') and a.status = 1 and a.show = 1 order by a.hot desc,a.id desc";
            }elseif($type == "tag"){//标签搜索
                $tag = $this->db->select("id,name")->from("bbs_article_tags")->where(array("id"=>$value))->order_by("id desc")->get()->row_array();
                $tag_name = $tag['name']; 
                $where .= "a.tags_name like '%$tag_name%' and a.status = 1 and a.show = 1 order by a.hot desc,a.id desc";
            }
            $sqlCount = "select a.* from tan_bbs_article a where ".$where;//构造查询结果总数
            $sqlData = "select a.id,a.authorid,a.title,a.summary,a.cat_id,a.thumb,a.tags_name,a.readnum,a.commentnum,a.likes,a.status,a.create_time,c.name cat_name,u.nickname from tan_bbs_article a left join tan_bbs_article_category c on c.id = a.cat_id left join tan_users_info u on u.user_id = a.authorid where ".$where." limit ".($pageIndex * $records_per_page).",$records_per_page";//构造查询结果记录
            $totalCount = $this->db->query($sqlCount)->num_rows();
            $list = $this->db->query($sqlData)->result_array();
            
            $html = "";
            foreach ($list as $key => $val){
                $tags_str = "";
                if($val['tags_name']){
                    $tags_arr = explode(",", $val['tags_name']);
                    foreach ($tags_arr as $v){
                        $v = explode("_", $v);
                        $tags_str .= "<a href='".web_url("p/tag-".$v[1])."' ".($tag['id'] == $v[1] ? "class='on'" : "").">$v[0]</a>";
                    }
                }
                $is_like = $this->bbs_userinfo ? (($this->db->query("select * from tan_bbs_like where article_id = $val[id] and user_id = ".$this->bbs_userinfo['user_id'])->num_rows()) ? 1 : 0) : 0;
                if($value == "latest"){
                    $create_time = $this->set_time($val['create_time']);
                }else{
                    $create_time = date("Y-m-d H:i",$val['create_time']);
                }
                $val['summary'] = str_replace(" ","",  mb_strcut($val["summary"], 0, 300, "utf-8"))."...";
                $html .= "<li class='article-con'>
                            <a href='".web_url("p/".encrypt_article_id($val['id']))."' target='_blank' class='img fl'><img class='lazy' data-original='$val[thumb]'/></a>
                            <div class='con fr'>
                                <a href='".web_url("p/".encrypt_article_id($val['id']))."' target='_blank' class='title'>$val[title]</a>
                                <a href='".web_url("p/".encrypt_article_id($val['id']))."' target='_blank' class='txt textnum110'>".  str_replace(" ","",$val[summary])."</a>
                                <div class='label mt10'>
                                    <div class='label-list'>$tags_str</div>
                                    <div class='clear'></div>
                                </div>
                                <div class='user mt15'>
                                	<b class='icon-index section fl mr5'></b>
                                    <a href='".web_url("p/cat-".$val['cat_id'])."' class='fl cat'>$val[cat_name]</a>
                                    <a href='".web_url("u/".encrypt_user_id($val['authorid']))."' class='name fl ml15'>by：$val[nickname]</a>
                                    <b class='icon-index eye fl ml15'></b>
                                    <span class='num fl ml5'>$val[readnum]</span>
                                    <b class='icon-index message fl ml15'></b>
                                    <span class='num fl ml5'>$val[commentnum]</span>
                                    <a href='javascript:void(0);' class='zan fr'><span>$val[likes]</span><b class='icon-index fr like-btn' data-aid='".encrypt_article_id($val['id'])."' data-auid='".encrypt_user_id($val['authorid'])."' data-value='$is_like'></b></a>
                                    <div class='clear'></div>
                                </div>
                            </div>
                            <div class='clear'></div>
                        </li>";
            }
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $html,
                    "goto" => true,
                    "totalPage" => ceil($totalCount/$records_per_page)
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }
    //获取问答列表
    function ajax_fetch_wenda(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $type = isset($_REQUEST['Type']) ? trim($_REQUEST['Type']) : "hot";
            $key = isset($_REQUEST['Key']) ? trim($_REQUEST['Key']) : "";
            $value = isset($_REQUEST['Value']) ? trim($_REQUEST['Value']) : "";
            $records_per_page = 12;
            if($type == "act"){
                $where = "w.tags_name like '%溜溜活动%' and w.status = 1 and w.is_show = 1 order by w.id desc";
            }else{
                if($key == "tag"){//标签搜索
                    $tag = $this->db->select("id,name")->from("bbs_wenda_tags")->where(array("id"=>$value))->order_by("id desc")->get()->row_array();
                    $tag_name = $tag['name']; 
                    if($type == "hot"){
                        $where = "w.tags_name like '%$tag_name%' and w.hot = 1 and w.status = 1 and w.is_show = 1 order by w.sort desc,w.id desc";
                    }elseif($type == "lasest"){
                        $where = "w.tags_name like '%$tag_name%' and w.status = 1 and w.is_show = 1 order by w.id desc";
                    }else{
                        $where = "w.tags_name like '%$tag_name%' and w.status = 1 and w.is_show = 1 and w.answernum = 0 order by w.id desc";
                    }

                }elseif($key == "kw"){//标题关键字搜索
                    if($type == "all"){
                        $where = "(w.title like '%$value%' or w.tags_name like '%$value%') and w.status = 1 and w.is_show = 1 order by w.sort desc,w.id desc";
                    }elseif($type == "lasest"){
                        $where = "(w.title like '%$value%' or w.tags_name like '%$value%') and w.status = 1 and w.is_show = 1 order by w.id desc";
                    }else{
                        $where = "(w.title like '%$value%' or w.tags_name like '%$value%') and w.status = 1 and w.is_show = 1 and w.answernum = 0 order by w.id desc";
                    }
                }else{//默认搜索
                    if($type == "hot"){
                        $where = "w.hot = 1 and w.status = 1 and w.is_show = 1 order by w.sort desc,w.id desc";
                    }elseif($type == "lasest"){
                        $where = "w.status = 1 and w.is_show = 1 order by w.id desc";
                    }else{
                        $where = "w.status = 1 and w.is_show = 1 and w.answernum = 0 order by w.id desc";
                    }
                }
            }
            
            $sqlCount = "select w.* from tan_bbs_wenda w where $where";
            $sqlList = "select w.id,w.questioner_id,w.title,w.summary,w.tags_name,w.create_time,w.readnum,w.answernum,w.likes,w.focusnum,w.answer_id,w.answer_uid,u1.nickname wd_nickname,u1.head_img wd_headimg from tan_bbs_wenda w left join tan_users_info u1 on u1.user_id = w.questioner_id where $where limit ".($pageIndex * $records_per_page).",$records_per_page";//构造查询结果记录;
            $totalCount = $this->db->query($sqlCount)->num_rows();
            $list = $this->db->query($sqlList)->result_array();
            
            $html = $this->set_wenda_str($type,$value,$list);
            
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $html,
                    "goto" => true,
                    "totalPage" => ceil($totalCount/$records_per_page)
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }
    //获取问答列表
    function ajax_fetch_exposure(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $type = isset($_REQUEST['Type']) ? trim($_REQUEST['Type']) : "hot";
            $key = isset($_REQUEST['Key']) ? trim($_REQUEST['Key']) : "";
            $value = isset($_REQUEST['Value']) ? trim($_REQUEST['Value']) : "";
            $records_per_page = 12;
            if($type == "act"){
                $where = "w.tags_name like '%溜溜活动%' and w.status = 1 and w.is_show = 1 order by w.id desc";
            }else{
                if($key == "tag"){//标签搜索
                    $tag = $this->db->select("id,name")->from("bbs_exposure_tags")->where(array("id"=>$value))->order_by("id desc")->get()->row_array();
                    $tag_name = $tag['name'];
                    if($type == "hot"){
                        $where = "w.tags_name like '%$tag_name%' and w.hot = 1 and w.status = 1 and w.is_show = 1 order by w.sort desc,w.id desc";
                    }elseif($type == "lasest"){
                        $where = "w.tags_name like '%$tag_name%' and w.status = 1 and w.is_show = 1 order by w.id desc";
                    }else{
                        $where = "w.tags_name like '%$tag_name%' and w.status = 1 and w.is_show = 1 and w.answernum = 0 order by w.id desc";
                    }

                }elseif($key == "kw"){//标题关键字搜索
                    if($type == "all"){
                        $where = "(w.title like '%$value%' or w.tags_name like '%$value%') and w.status = 1 and w.is_show = 1 order by w.sort desc,w.id desc";
                    }elseif($type == "lasest"){
                        $where = "(w.title like '%$value%' or w.tags_name like '%$value%') and w.status = 1 and w.is_show = 1 order by w.id desc";
                    }else{
                        $where = "(w.title like '%$value%' or w.tags_name like '%$value%') and w.status = 1 and w.is_show = 1 and w.answernum = 0 order by w.id desc";
                    }
                }else{//默认搜索
                    if($type == "hot"){
                        $where = "w.hot = 1 and w.status = 1 and w.is_show = 1 order by w.sort desc,w.id desc";
                    }elseif($type == "lasest"){
                        $where = "w.status = 1 and w.is_show = 1 order by w.id desc";
                    }else{
                        $where = "w.status = 1 and w.is_show = 1 and w.answernum = 0 order by w.id desc";
                    }
                }
            }

            $sqlCount = "select w.* from tan_bbs_exposure w where $where";
            $sqlList = "select w.id,w.questioner_id,w.title,w.summary,w.tags_name,w.create_time,w.readnum,w.answernum,w.likes,w.focusnum,w.answer_id,w.answer_uid,u1.nickname wd_nickname,u1.head_img wd_headimg from tan_bbs_exposure w left join tan_users_info u1 on u1.user_id = w.questioner_id where $where limit ".($pageIndex * $records_per_page).",$records_per_page";//构造查询结果记录;
            $totalCount = $this->db->query($sqlCount)->num_rows();
            $list = $this->db->query($sqlList)->result_array();

            $html = $this->set_exposure_str($type,$value,$list);

            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $html,
                    "goto" => true,
                    "totalPage" => ceil($totalCount/$records_per_page)
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }
    //获取问答答案列表
    function ajax_fetch_answer(){
        if($_POST){
            $wenda_id = isset($_POST['wendaId']) ? trim($_POST['wendaId']) : 0;
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $answerId = isset($_REQUEST['answerId']) ? trim($_REQUEST['answerId']) : 0;//目标答案，不在答案列表页
            $wenda_id = decrypt_wenda_id($wenda_id);
            
            $wenda = $this->db->select("id,questioner_id,answer_id,title,answernum")->from("bbs_wenda")->where(array("id"=>$wenda_id))->order_by("id")->get()->row_array();
            if($answerId){
                $answerId = decrypt_answer_id($answerId);
                $not_in = "and a.id not in ($answerId)";
            }else{
                $not_in = "";
            }
            $records_per_page = 30;
            $totalCount = $this->db->query("select a.* from tan_bbs_wenda_answer a where a.wenda_id = $wenda_id and a.is_show = 1 ".$not_in." order by a.id asc")->num_rows();
            
            $select_str = "a.id,a.user_id,a.content,a.likes,a.commentnum,a.is_answer,a.create_time,u.nickname,u.head_img";
            $list = $this->db->query("select $select_str from tan_bbs_wenda_answer a left join tan_users_info u on u.user_id = a.user_id where a.wenda_id = $wenda_id and a.is_show = 1 ".$not_in." order by a.is_answer desc,a.likes desc,a.id desc limit ".($pageIndex * $records_per_page).",$records_per_page")->result_array();
            $html = "";
            foreach ($list as $key=>$val){
                
                $share_url = share_url("wenda/". encrypt_wenda_id($wenda['id'])."/answer-".  encrypt_answer_id($val['id']));
                
                $is_like = $this->bbs_userinfo['user_id'] ?($this->db->select("*")->from("bbs_wenda_answer_like")->where(array("user_id"=>$this->bbs_userinfo['user_id'],"answer_id"=>$val['id'],"is_del"=>1))->order_by("id")->get()->num_rows() ? 1 : 0) : 0;
                $answer_id = encrypt_answer_id($val['id']);
                $answer_uid = encrypt_user_id($val['user_id']);
                $html .= "<li id='answer-$answer_id' data-aid='$answer_id' data-auid='$answer_uid' >";
                $html .= "  <div class='who-reply'>";
                $html .= "      <a href='".web_url("u/".$answer_uid)."' target='_blank'><img src='$val[head_img]' /></a>";
                $html .= "      <a class='btn-praise ".($is_like ? "dianzan" : "bp-default")."' onselectstart='return false' data-value='$is_like'><b class='icon-com ".($is_like ? "dianzan" : "icon-detail-praise")."'></b><span class='".($is_like ? "colfff" : "collike")."'>$val[likes]</span></a>";
                $html .= "  </div>";
                $html .= "  <div class='reply-content'>";
                $html .= "      <div class='reply-info'>";
                $html .= "          <div class='replier-bar'>";
                $html .= "              <a class='mr5' href='".web_url("u/".$answer_uid)."' target='_blank'>$val[nickname]</a>";
                $html .= "              <a class='replier-level' href='javascript:void(0);' target='_blank' rel='nofollow'></a>";
                if($val['is_answer']){
                    $html .= "              <span class='adopted fr'>最佳答案</span>";
                }else{
                    if($this->bbs_userinfo['user_id'] == $wenda['questioner_id'] && !$wenda['answer_id']){
                        $html .= "          <span class='adopt fr best-answer-btn'>采纳为答案</span>";
                    }
                }
                
                
                $html .= "              <div class='clear'></div>";
                $html .= "          </div>";
                $html .= "      </div>";
                $html .= "      <div class='reply-detail'>$val[content]</div>";
                $html .= "      <div class='share-report show-report'>";
                $html .= "          <div class='q-share fl'>";
                $html .= "              <a href='javascript:void(0);' class='comment-share share'><b class='icon-com icon-ask-share'></b>分享</a>";
                $html .= "              <div class='share-pop share'>";
                $html .= "                  <a class='sina icon-tab icon-share-sina' title='分享到新浪微博' data-key='wb' data-title='#弹溜溜问答专栏#《$wenda[title]》发现一个超精彩回答来自：$val[nickname]' data-content='#共$wenda[answernum]人回答#' data-ref='$share_url'></a>";
                $html .= "                  <a class='qzone icon-tab icon-share-qzone' title='分享到QQ空间' data-key='qq' data-title='#弹溜溜问答专栏#《$wenda[title]》发现一个超精彩回答来自：$val[nickname]' data-content='#共$wenda[answernum]人回答#' data-ref='$share_url'></a>";
                $html .= "                  <a class='sweixin icon-tab icon-share-wechat' title='分享到微信' data-key='wx' data-wx-qrcode='/trcode.html?text=".urlencode($share_url)."&size=150&level=H'></a>";
                $html .= "              </div>";
                $html .= "          </div>";
                $html .= "          <a href='javascript:void(0);' class='q-invite mr5 _add_commit comment-wrap-btn'><b class='icon-com icon-comment'></b><span class='_ad_com'>".($val['commentnum'] ? $val['commentnum']."条评论" : "添加评论")."</span></a>";
                $html .= "          <span class='release-time mr5'>发布于 ".date("Y-m-d H:i",$val['create_time'])."</span>";
                $html .= "          <a style='display: none;' class='_report' data-rel='".web_url("wenda/".encrypt_wenda_id($wenda_id)."/answer-".  encrypt_answer_id($val['id']))."'>举报</a>";
                $html .= "      </div>";
                $html .= "      <div class='commit-wrap _uncommit comment-wrap-box' ".($val['commentnum'] ? "" : "style='display:none;'").">";
                $html .= "          <b class='arrow'><i></i></b>";
                if($val['commentnum']){
                    $replys = $this->db->select("r.*,u1.head_img,u1.nickname nickname1,u2.nickname nickname2")->from("bbs_wenda_reply r")->join("users_info u1","u1.user_id=r.user_id","left")->join("users_info u2","u2.user_id=r.reply_uid","left")->where(array("answer_id"=>$val['id'],"is_show"=>1))->order_by("id asc")->limit(2)->get()->result_array();
                }else{
                    $replys = array();
                }
                $html .= "          <ul class='commit-list _commit_list reply-list-box'>";
                foreach ($replys as $k=>$reply){
                    $answer_reply_id = encrypt_answer_reply_id($reply['id']);
                    $time_str = $this->set_time_two($reply['create_time']);
                    $html .= "          <li id='answer-reply-$answer_reply_id' data-rid='$answer_reply_id'>";
                    $html .= "              <div class='commit-user'><a href='".web_url("u/".encrypt_user_id($reply['user_id']))."' target='_blank'><img src='$reply[head_img]'/></a></div>";
                    $html .= "              <dl>";
                    $html .= "                  <dt class='replier-bar'>";
                    $html .= "                      <a href='".web_url("u/".encrypt_user_id($reply['user_id']))."' target='_blank'>$reply[nickname1]</a>";
                    $html .= "                      <a href='javascript:void(0);' class='replier-level' target='_blank'></a>：";
                    if($reply['reply_uid']){
                        $html .= "                  <a target='_blank' href='".web_url("u/".encrypt_user_id($reply['reply_uid']))."'>@$reply[nickname2]</a>";
                    }
                    $html .= "                      $reply[content]";
                    $html .= "                  </dt>";
                    $html .= "                  <dd>";
                    $html .= "                      <div class='c-info show-report'>";
                    $html .= "                          <span class='c-time fl col999'>$time_str</span>";
                    $html .= "                          <a class='c-reply fr reply-item-r' data-rid='$answer_reply_id' data-rname='@$reply[nickname1]'>回复</a>";
                    $html .= "                          <a style='display: none;' class='c-reply _report fr' data-rel='".  web_url("wenda/".encrypt_wenda_id($wenda_id)."/answer/".  encrypt_answer_id($val['id'])."/reply-". $answer_reply_id)."'>举报</a>";
                    $html .= "                          <div class='clear'></div>";
                    $html .= "                      </div>";
                    $html .= "                  </dd>";
                    $html .= "              </dl>";
                    $html .= "          </li>";
                }
                $html .= "          </ul>";
                if($val['commentnum'] > 2){
                    $html .= "      <div class='commit-more'>";
                    $html .= "          <a class='acommit-more answer-relay-more'>查看更多&gt;&gt;</a>";
                    $html .= "      </div>";
                }
                $html .= "          <div class='reply-page' id='page_reply_pagination_$answer_id'></div>";
                $html .= "          <div class='commit-add'>";
                $html .= "              <div class='commit-word'>";
                $html .= "                  <textarea class='reply-woerd' placeholder=''></textarea>";
                $html .= "              </div>";
                $html .= "              <p class='word-count mt15'><span></span>0&nbsp;字</p>";
                $html .= "              <input class='btn-commit mt10 answer-relay-btn' value='回复' type='button' data-rid='' data-unvilad='提交中'>";
                $html .= "              <div class='clear'></div>";
                $html .= "          </div>";
                $html .= "      </div>";
                $html .= "   </div>";
                $html .= "</li>";
            }
            $totalCount = $answerId ? (1 + $totalCount) : $totalCount;
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $html,
                    "goto" => true,
                    "totalPage" => ceil($totalCount/$records_per_page)
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }
//获取问答答案列表
    function ajax_fetch_exposure_answer(){
        if($_POST){
            $wenda_id = isset($_POST['wendaId']) ? trim($_POST['wendaId']) : 0;
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $answerId = isset($_REQUEST['answerId']) ? trim($_REQUEST['answerId']) : 0;//目标答案，不在答案列表页
            $wenda_id = decrypt_wenda_id($wenda_id);

            $wenda = $this->db->select("id,questioner_id,answer_id,title,answernum")->from("bbs_exposure")->where(array("id"=>$wenda_id))->order_by("id")->get()->row_array();
            if($answerId){
                $answerId = decrypt_answer_id($answerId);
                $not_in = "and a.id not in ($answerId)";
            }else{
                $not_in = "";
            }
            $records_per_page = 30;
            $totalCount = $this->db->query("select a.* from tan_bbs_exposure_answer a where a.wenda_id = $wenda_id and a.is_show = 1 ".$not_in." order by a.id asc")->num_rows();

            $select_str = "a.id,a.user_id,a.content,a.likes,a.commentnum,a.is_answer,a.create_time,u.nickname,u.head_img";
            $list = $this->db->query("select $select_str from tan_bbs_exposure_answer a left join tan_users_info u on u.user_id = a.user_id where a.wenda_id = $wenda_id and a.is_show = 1 ".$not_in." order by a.is_answer desc,a.likes desc,a.id desc limit ".($pageIndex * $records_per_page).",$records_per_page")->result_array();
            $html = "";
            foreach ($list as $key=>$val){

                $share_url = share_url("exposure/". encrypt_wenda_id($wenda['id'])."/answer-".  encrypt_answer_id($val['id']));

                $is_like = $this->bbs_userinfo['user_id'] ?($this->db->select("*")->from("bbs_exposure_answer_like")->where(array("user_id"=>$this->bbs_userinfo['user_id'],"answer_id"=>$val['id'],"is_del"=>1))->order_by("id")->get()->num_rows() ? 1 : 0) : 0;
                $answer_id = encrypt_answer_id($val['id']);
                $answer_uid = encrypt_user_id($val['user_id']);
                $html .= "<li id='answer-$answer_id' data-aid='$answer_id' data-auid='$answer_uid' >";
                $html .= "  <div class='who-reply'>";
                $html .= "      <a href='".web_url("u/".$answer_uid)."' target='_blank'><img src='$val[head_img]' /></a>";
                $html .= "      <a class='btn-praise ".($is_like ? "dianzan" : "bp-default")."' data-type='1' onselectstart='return false' data-value='$is_like'><b class='icon-com ".($is_like ? "dianzan" : "icon-detail-praise")."'></b><span class='".($is_like ? "colfff" : "collike")."'>$val[likes]</span></a>";
                $html .= "  </div>";
                $html .= "  <div class='reply-content'>";
                $html .= "      <div class='reply-info'>";
                $html .= "          <div class='replier-bar'>";
                $html .= "              <a class='mr5' href='".web_url("u/".$answer_uid)."' target='_blank'>$val[nickname]</a>";
                $html .= "              <a class='replier-level' href='javascript:void(0);' target='_blank' rel='nofollow'></a>";
//                if($val['is_answer']){
//                    $html .= "              <span class='adopted fr'>最佳答案</span>";
//                }else{
//                    if($this->bbs_userinfo['user_id'] == $wenda['questioner_id'] && !$wenda['answer_id']){
//                        $html .= "          <span class='adopt fr best-answer-btn'>采纳为答案</span>";
//                    }
//                }


                $html .= "              <div class='clear'></div>";
                $html .= "          </div>";
                $html .= "      </div>";
                $html .= "      <div class='reply-detail'>$val[content]</div>";
                $html .= "      <div class='share-report show-report'>";
                $html .= "          <div class='q-share fl'>";
                $html .= "              <a href='javascript:void(0);' class='comment-share share'><b class='icon-com icon-ask-share'></b>分享</a>";
                $html .= "              <div class='share-pop share'>";
                $html .= "                  <a class='sina icon-tab icon-share-sina' title='分享到新浪微博' data-key='wb' data-title='#弹溜溜无忧专栏#《$wenda[title]》发现一个超精彩评论来自：$val[nickname]' data-content='#共$wenda[answernum]人回复#' data-ref='$share_url'></a>";
                $html .= "                  <a class='qzone icon-tab icon-share-qzone' title='分享到QQ空间' data-key='qq' data-title='#弹溜溜无忧专栏#《$wenda[title]》发现一个超精彩评论来自：$val[nickname]' data-content='#共$wenda[answernum]人回复#' data-ref='$share_url'></a>";
                $html .= "                  <a class='sweixin icon-tab icon-share-wechat' title='分享到微信' data-key='wx' data-wx-qrcode='/trcode.html?text=".urlencode($share_url)."&size=150&level=H'></a>";
                $html .= "              </div>";
                $html .= "          </div>";
                $html .= "          <a href='javascript:void(0);' class='q-invite mr5 _add_commit comment-wrap-btn'><b class='icon-com icon-comment'></b><span class='_ad_com'>".($val['commentnum'] ? $val['commentnum']."条回复" : "添加回复")."</span></a>";
                $html .= "          <span class='release-time mr5'>发布于 ".date("Y-m-d H:i",$val['create_time'])."</span>";
                $html .= "          <a style='display: none;' class='_report' data-rel='".web_url("exposure/".encrypt_wenda_id($wenda_id)."/answer-".  encrypt_answer_id($val['id']))."'>举报</a>";
                $html .= "      </div>";
                $html .= "      <div class='commit-wrap _uncommit comment-wrap-box' ".($val['commentnum'] ? "" : "style='display:none;'").">";
                $html .= "          <b class='arrow'><i></i></b>";
                if($val['commentnum']){
                    $replys = $this->db->select("r.*,u1.head_img,u1.nickname nickname1,u2.nickname nickname2")->from("bbs_exposure_reply r")->join("users_info u1","u1.user_id=r.user_id","left")->join("users_info u2","u2.user_id=r.reply_uid","left")->where(array("answer_id"=>$val['id'],"is_show"=>1))->order_by("id asc")->limit(2)->get()->result_array();
                }else{
                    $replys = array();
                }
                $html .= "          <ul class='commit-list _commit_list reply-list-box'>";
                foreach ($replys as $k=>$reply){
                    $answer_reply_id = encrypt_answer_reply_id($reply['id']);
                    $time_str = $this->set_time_two($reply['create_time']);
                    $html .= "          <li id='answer-reply-$answer_reply_id' data-rid='$answer_reply_id'>";
                    $html .= "              <div class='commit-user'><a href='".web_url("u/".encrypt_user_id($reply['user_id']))."' target='_blank'><img src='$reply[head_img]'/></a></div>";
                    $html .= "              <dl>";
                    $html .= "                  <dt class='replier-bar'>";
                    $html .= "                      <a href='".web_url("u/".encrypt_user_id($reply['user_id']))."' target='_blank'>$reply[nickname1]</a>";
                    $html .= "                      <a href='javascript:void(0);' class='replier-level' target='_blank'></a>：";
                    if($reply['reply_uid']){
                        $html .= "                  <a target='_blank' href='".web_url("u/".encrypt_user_id($reply['reply_uid']))."'>@$reply[nickname2]</a>";
                    }
                    $html .= "                      $reply[content]";
                    $html .= "                  </dt>";
                    $html .= "                  <dd>";
                    $html .= "                      <div class='c-info show-report'>";
                    $html .= "                          <span class='c-time fl col999'>$time_str</span>";
                    $html .= "                          <a class='c-reply fr exposure-reply-item-r' data-rid='$answer_reply_id' data-rname='@$reply[nickname1]'>回复</a>";
                    $html .= "                          <a style='display: none;' class='c-reply _report fr' data-rel='".  web_url("exposure/".encrypt_wenda_id($wenda_id)."/answer/".  encrypt_answer_id($val['id'])."/reply-". $answer_reply_id)."'>举报</a>";
                    $html .= "                          <div class='clear'></div>";
                    $html .= "                      </div>";
                    $html .= "                  </dd>";
                    $html .= "              </dl>";
                    $html .= "          </li>";
                }
                $html .= "          </ul>";
                if($val['commentnum'] > 2){
                    $html .= "      <div class='commit-more'>";
                    $html .= "          <a class='acommit-more exposure_answer-relay-more'>查看更多&gt;&gt;</a>";
                    $html .= "      </div>";
                }
                $html .= "          <div class='reply-page' id='page_reply_pagination_$answer_id'></div>";
                $html .= "          <div class='commit-add'>";
                $html .= "              <div class='commit-word'>";
                $html .= "                  <textarea class='reply-woerd' placeholder=''></textarea>";
                $html .= "              </div>";
                $html .= "              <p class='word-count mt15'><span></span>0&nbsp;字</p>";
                $html .= "              <input class='btn-commit mt10 exposure_answer-relay-btn' value='提交回复' type='button' data-rid='' data-unvilad='提交中'>";
                $html .= "              <div class='clear'></div>";
                $html .= "          </div>";
                $html .= "      </div>";
                $html .= "   </div>";
                $html .= "</li>";
            }
            $totalCount = $answerId ? (1 + $totalCount) : $totalCount;
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $html,
                    "goto" => true,
                    "totalPage" => ceil($totalCount/$records_per_page)
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }
    
    //加载问答评论
    function ajax_fetch_reply(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $answerId = isset($_REQUEST['answerId']) ? trim($_REQUEST['answerId']) : 0;
            $answerId = decrypt_answer_id($answerId);
            $records_per_page = 12;
            $totalCount = $this->db->select("*")->from("bbs_wenda_reply")->where(array("answer_id"=>$answerId,"is_show"=>1))->order_by("id asc")->get()->num_rows();
            $list = $this->db->select("r.*,u1.head_img,u1.nickname nickname1,u2.nickname nickname2")->from("bbs_wenda_reply r")->join("users_info u1","u1.user_id=r.user_id","left")->join("users_info u2","u2.user_id=r.reply_uid","left")->where(array("r.answer_id"=>$answerId,"r.is_show"=>1))->order_by("id asc")->limit($records_per_page,($pageIndex)*$records_per_page)->get()->result_array();
            $html = "";
            foreach ($list as $key=>$val){
                $reply_id = encrypt_answer_reply_id($val['id']);
                $time_str = $this->set_time_two($val['create_time']);
                $html .= "<li id='answer-reply-$reply_id' data-rid='$reply_id'>
                            <div class='commit-user'><a href='".web_url("u/".encrypt_user_id($val['user_id']))."' target='_blank'><img src='$val[head_img]'/></a></div>
                            <dl>
                                <dt class='replier-bar'>
                                    <a href='".web_url("u/".encrypt_user_id($val['user_id']))."' target='_blank'>$val[nickname1]</a>
                                    <a href='javascript:void(0);' class='replier-level' target='_blank'></a>：".($val['reply_id'] ? "<a target='_blank' href='".web_url("u/".encrypt_user_id($val['reply_uid']))."'>@$val[nickname2]</a>" : "")."
                                    $val[content]
                                </dt>
                                <dd>
                                    <div class='c-info show-report'>
                                        <span class='c-time fl col999'>$time_str</span>
                                        <a class='c-reply fr reply-item-r' data-rid='$reply_id' data-rname='@$val[nickname1]'>回复</a>
                                        <a style='display: none;' class='c-reply _report fr' data-rel='". web_url("wenda/".encrypt_wenda_id($val['wenda_id'])."/answer/".  encrypt_answer_id($val['answer_id'])."/reply-".$reply_id)."'>举报</a>
                                        <div class='clear'></div>
                                    </div>
                                </dd>
                            </dl>
                        </li>";
            }
        }
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "totalCount" => $totalCount ? $totalCount : 0,
                "pageIndex" => $pageIndex,
                "htmlData" => $html,
                "goto" => true,
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    function ajax_fetch_exposure_reply(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $answerId = isset($_REQUEST['answerId']) ? trim($_REQUEST['answerId']) : 0;
            $answerId = decrypt_answer_id($answerId);
            $records_per_page = 12;
            $totalCount = $this->db->select("*")->from("bbs_exposure_reply")->where(array("answer_id"=>$answerId,"is_show"=>1))->order_by("id asc")->get()->num_rows();
            $list = $this->db->select("r.*,u1.head_img,u1.nickname nickname1,u2.nickname nickname2")->from("bbs_exposure_reply r")->join("users_info u1","u1.user_id=r.user_id","left")->join("users_info u2","u2.user_id=r.reply_uid","left")->where(array("r.answer_id"=>$answerId,"r.is_show"=>1))->order_by("id asc")->limit($records_per_page,($pageIndex)*$records_per_page)->get()->result_array();
            $html = "";
            foreach ($list as $key=>$val){
                $reply_id = encrypt_answer_reply_id($val['id']);
                $time_str = $this->set_time_two($val['create_time']);
                $html .= "<li id='answer-reply-$reply_id' data-rid='$reply_id'>
                            <div class='commit-user'><a href='".web_url("u/".encrypt_user_id($val['user_id']))."' target='_blank'><img src='$val[head_img]'/></a></div>
                            <dl>
                                <dt class='replier-bar'>
                                    <a href='".web_url("u/".encrypt_user_id($val['user_id']))."' target='_blank'>$val[nickname1]</a>
                                    <a href='javascript:void(0);' class='replier-level' target='_blank'></a>：".($val['reply_id'] ? "<a target='_blank' href='".web_url("u/".encrypt_user_id($val['reply_uid']))."'>@$val[nickname2]</a>" : "")."
                                    $val[content]
                                </dt>
                                <dd>
                                    <div class='c-info show-report'>
                                        <span class='c-time fl col999'>$time_str</span>
                                        <a class='c-reply fr reply-item-r' data-rid='$reply_id' data-rname='@$val[nickname1]'>回复</a>
                                        <a style='display: none;' class='c-reply _report fr' data-rel='". web_url("exposure/".encrypt_wenda_id($val['wenda_id'])."/answer/".  encrypt_answer_id($val['answer_id'])."/reply-".$reply_id)."'>举报</a>
                                        <div class='clear'></div>
                                    </div>
                                </dd>
                            </dl>
                        </li>";
            }
        }
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "totalCount" => $totalCount ? $totalCount : 0,
                "pageIndex" => $pageIndex,
                "htmlData" => $html,
                "goto" => true,
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    //获取自己的粉丝
    function get_self_fans(){
        $this->is_login();
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $records_per_page = 16;
        $totalCount = $this->bbs_account_model->get_account_user_fans_count(array("user_id"=>$this->bbs_userinfo['user_id'],"is_del"=>1));
        $list = $this->bbs_account_model->get_account_user_fans_list(array("bbs_fans.user_id"=>$this->bbs_userinfo['user_id'],"bbs_fans.is_del"=>1),$pageIndex * $records_per_page,$records_per_page);
        $html = "";
        foreach ($list as $key=>$val){
            $user_id = encrypt_user_id($val['followuid']);
            //验证是否互相关注
            $is_fan = $this->bbs_user_model->get_fan_status(array("user_id"=>$val['followuid'],"followuid"=>$this->bbs_userinfo['user_id'],"is_del"=>1));
            $is_fan = $is_fan ? 1 : 0;
            $html .= "<li data-uuid='".$user_id."'>
                            <div class='head'>
                                <a href='".web_url("u/".$user_id)."' target='blank' class='header'>
                                    <img src='".$val['head_img']."'/>
                                </a>
                            </div>
                            <div class='name'>
                                <a href='".web_url("u/".$user_id)."'>".$val['nickname']."</a>
                            </div>
                            <div class='bot overhide'>
                                <a href='".web_url("u/".$user_id."/arts")."' class='post'><b>".($val['articles_count'] ? $val['articles_count'] : 0)."</b>帖子</a>
                                <a href='".web_url("u/".$user_id."/fans")."' class='fans'><b>".($val['fans_count'] ? $val['fans_count'] : 0)."</b>粉丝</a>
                                <a href='".web_url("u/".$user_id."/question")."' class='problem' style='border-right: 0;'><b>".($val['question_count'] ? $val['question_count'] : 0)."</b>问答</a>
                            </div>
                            <div class='btn'>
                                <a href='javascript:void(0);' class='".($is_fan ? "follow-btn" : "unfollow-btn")." page-follow-btn' data-value='$is_fan'>".($is_fan ? "已关注" : "未关注")."</a>
                                <a href='javascript:void(0);' class='message-btn' data-url='".web_url("chats/".$val['salt'])."'>发私信</a>
                            </div>
                        </li>";
            
        }
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "totalCount" => $totalCount ? $totalCount : 0,
                "pageIndex" => $pageIndex,
                "htmlData" => $html,
                "goto" => true,
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    //获取自己的关注
    function get_self_follows(){
        $this->is_login();
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $records_per_page = 16;
        $totalCount = $this->bbs_account_model->get_account_user_focus_count(array("followuid"=>$this->bbs_userinfo['user_id'],"is_del"=>1));
        $list = $this->bbs_account_model->get_account_user_focus_list(array("bbs_fans.followuid"=>$this->bbs_userinfo['user_id'],"bbs_fans.is_del"=>1),$pageIndex * $records_per_page,$records_per_page);
        $html = "";
        foreach ($list as $key=>$val){
            $user_id = encrypt_user_id($val['user_id']);
            $html .= "<li data-uuid='".$user_id."'>
                            <div class='head'>
                                <a href='".web_url("u/".$user_id)."' target='blank' class='header'>
                                    <img src='".$val['head_img']."'/>
                                </a>
                            </div>
                            <div class='name'>
                                <a href='".web_url("u/".$user_id)."'>".$val['nickname']."</a>
                            </div>
                            <div class='bot overhide'>
                                <a href='".web_url("u/".$user_id."/arts")."' class='post'><b>".($val['articles_count'] ? $val['articles_count'] : 0)."</b>帖子</a>
                                <a href='".web_url("u/".$user_id."/fans")."' class='fans'><b>".($val['fans_count'] ? $val['fans_count'] : 0)."</b>粉丝</a>
                                <a href='".web_url("u/".$user_id."/question")."' class='problem' style='border-right: 0;'><b>".($val['question_count'] ? $val['question_count'] : 0)."</b>问答</a>
                            </div>
                            <div class='btn'>
                                <a href='javascript:void(0);' class='follow-btn  page-follow-btn' data-value='1'>已关注</a>
                                <a href='javascript:void(0);' class='message-btn' data-url='".web_url("chats/".$val['salt'])."'>发私信</a>
                            </div>
                        </li>";
            
        }
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "totalCount" => $totalCount ? $totalCount : 0,
                "pageIndex" => $pageIndex,
                "htmlData" => $html,
                "goto" => true,
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    
    //获取他人的粉丝
    function get_ta_fans(){
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
        $uuid = decrypt_user_id($uuid);
        $records_per_page = 16;
        $totalCount = $this->bbs_account_model->get_account_user_fans_count(array("user_id"=>$uuid,"is_del"=>1));
        $list = $this->bbs_account_model->get_account_user_fans_list(array("bbs_fans.user_id"=>$uuid,"bbs_fans.is_del"=>1),$pageIndex * $records_per_page,$records_per_page);
        $html = "";
        foreach ($list as $key=>$val){
            $user_id = encrypt_user_id($val['followuid']);
            //验证是否互相关注
            $is_fan = $this->bbs_userinfo ? ($this->bbs_user_model->get_fan_status(array("user_id"=>$val['followuid'],"followuid"=>$this->bbs_userinfo['user_id'],"is_del"=>1)) ? 1 : 0) : 0;
            $html .= "<li data-uuid='".$user_id."'>
                            <div class='head'>
                                <a href='".web_url("u/".$user_id)."' target='blank' class='header'>
                                    <img src='".$val['head_img']."'/>
                                </a>
                            </div>
                            <div class='name'>
                                <a href='".web_url("u/".$user_id)."'>".$val['nickname']."</a>
                            </div>
                            <div class='bot overhide'>
                                <a href='".web_url("u/".$user_id."/arts")."' class='post'><b>".($val['articles_count'] ? $val['articles_count'] : 0)."</b>帖子</a>
                                <a href='".web_url("u/".$user_id."/fans")."' class='fans'><b>".($val['fans_count'] ? $val['fans_count'] : 0)."</b>粉丝</a>
                                <a href='".web_url("u/".$user_id."/question")."' class='problem' style='border-right: 0;'><b>".($val['following_count'] ? $val['following_count'] : 0)."</b>问答</a>
                            </div>
                            <div class='btn'>
                                <a href='javascript:void(0);' class='".($is_fan ? "follow-btn" : "unfollow-btn")." page-follow-btn' data-value='$is_fan'>".($is_fan ? "已关注" : "未关注")."</a>
                                <a href='javascript:void(0);' class='message-btn' data-url='".web_url("chats/".$val['salt'])."'>发私信</a>
                            </div>
                        </li>";
            
        }
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "totalCount" => $totalCount ? $totalCount : 0,
                "pageIndex" => $pageIndex,
                "htmlData" => $html,
                "goto" => true,
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    
     //获取自己的关注
    function get_ta_follows(){
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
        $uuid = decrypt_user_id($uuid);
        $records_per_page = 16;
        $totalCount = $this->bbs_account_model->get_account_user_focus_count(array("followuid"=>$uuid,"is_del"=>1));
        $list = $this->bbs_account_model->get_account_user_focus_list(array("bbs_fans.followuid"=>$uuid,"bbs_fans.is_del"=>1),$pageIndex * $records_per_page,$records_per_page);
        $html = "";
        foreach ($list as $key=>$val){
            $user_id = encrypt_user_id($val['user_id']);
            //验证是否互相关注
            $is_fan = $this->bbs_userinfo ? ($this->bbs_user_model->get_fan_status(array("user_id"=>$val['user_id'],"followuid"=>$this->bbs_userinfo['user_id'],"is_del"=>1)) ? 1 : 0) : 0;
            $html .= "<li data-uuid='".$user_id."'>
                            <div class='head'>
                                <a href='".web_url("u/".$user_id)."' target='blank' class='header'>
                                    <img src='".$val['head_img']."'/>
                                </a>
                            </div>
                            <div class='name'>
                                <a href='".web_url("u/".$user_id)."'>".$val['nickname']."</a>
                            </div>
                            <div class='bot overhide'>
                                <a href='".web_url("u/".$user_id."/arts")."' class='post'><b>".($val['articles_count'] ? $val['articles_count'] : 0)."</b>帖子</a>
                                <a href='".web_url("u/".$user_id."/fans")."' class='fans'><b>".($val['fans_count'] ? $val['fans_count'] : 0)."</b>粉丝</a>
                                <a href='".web_url("u/".$user_id."/question")."' class='problem' style='border-right: 0;'><b>".($val['following_count'] ? $val['following_count'] : 0)."</b>问答</a>
                            </div>
                            <div class='btn'>
                                <a href='javascript:void(0);' class='".($is_fan ? "follow-btn" : "unfollow-btn")." page-follow-btn' data-value='$is_fan'>".($is_fan ? "已关注" : "未关注")."</a>
                                <a href='javascript:void(0);' class='message-btn' data-url='".web_url("chats/".$val['salt'])."'>发私信</a>
                            </div>
                        </li>";
            
        }
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "totalCount" => $totalCount ? $totalCount : 0,
                "pageIndex" => $pageIndex,
                "htmlData" => $html,
                "goto" => true,
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    
    //搜索文章标签
    function seach_arts_tag(){
        $key_tag = isset($_GET['tag_key']) ? trim($_GET['tag_key']) : "";
        if(!$key_tag){
            $mess['reqStatus'] = true;
            $mess['seachRes'] = "";
            echo JSON($mess);exit;
        }
        $key_tag = strtolower($key_tag);//将所有大写字母转为小写
        
        if(preg_match("/^[a-z0-9]+$/",$key_tag)){//字母或数字查询
            if(strlen($key_tag) == 1){
                $colum = "letter_first";
            }else{
                $colum = "letter_all";
            }
        }else{//其他条件查询
            $colum = "name";
        }
        $tags = $this->db->select("name,id")->from("bbs_article_tags")->where(array())->like($colum, $key_tag, 'both')->order_by("sort desc")->get()->result_array();
        $seach_html = "";
        foreach ($tags as $key=>$val){
            $seach_html .= "<a href='javascript:void(0);' seach-name='".$val['name']."' seach-tid='".$val['id']."'>".$val['name']."</a>";
        }
        
        $mess['reqStatus'] = true;
        $mess['seachRes'] = $seach_html;
        echo json_encode($mess,JSON_HEX_TAG);die;
        
    }
    //搜索问答标签
    function seach_wenda_tag(){
        $key_tag = isset($_GET['tag_key']) ? trim($_GET['tag_key']) : "";
        if(!$key_tag){
            $mess['reqStatus'] = true;
            $mess['seachRes'] = "";
            echo JSON($mess);exit;
        }
        $key_tag = strtolower($key_tag);//将所有大写字母转为小写
        
        if(preg_match("/^[a-z0-9]+$/",$key_tag)){//字母或数字查询
            if(strlen($key_tag) == 1){
                $colum = "letter_first";
            }else{
                $colum = "letter_all";
            }
        }else{//其他条件查询
            $colum = "name";
        }
        $tags = $this->db->select("name,id")->from("bbs_wenda_tags")->where(array())->like($colum, $key_tag, 'both')->order_by("sort desc")->get()->result_array();
        $seach_html = "";
        foreach ($tags as $key=>$val){
            if($val['name'] == "溜溜活动" && !$this->bbs_userinfo['is_official']){
                continue;
            }else{
                $seach_html .= "<a href='javascript:void(0);' seach-name='".$val['name']."' seach-tid='".$val['id']."'>".$val['name']."</a>";
            }
            
        }
        
        $mess['reqStatus'] = true;
        $mess['seachRes'] = $seach_html;
        echo json_encode($mess,JSON_HEX_TAG);die;
    }
    
    
    //草稿箱
    function get_drafts(){
        $this->is_login();
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $user_id = $this->bbs_userinfo['user_id'];
        $records_per_page = 5;
        $totalCount = $this->db->select("*")->from("bbs_article_drafts")->where(array("authorid"=>$user_id))->order_by("create_time desc")->get()->num_rows();
        $list = $this->db->select("*")->from("bbs_article_drafts")->where(array("authorid"=>$user_id))->order_by("create_time desc")->limit($records_per_page,$records_per_page*$pageIndex)->get()->result_array();
        $html = "";
        foreach ($list as $key=>$val){
            $html .= "<li>
                            <a href='javascript:void(0);' class='title fl'>".$val['title']."</a>
                            <a href='".web_url("post/boxs/".$val['id'])."' class='icon-index modify fr ml20'></a>
                            <a href='javascript:void(0);' class='icon-index del fr' onclick='delete_get_drafts(".$val['id'].",this);'></a>
                            <p class='clear num mt10'>".date("Y-m-d H:i:s",$val['create_time'])."</p>
                        </li>";
        }
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "totalCount" => $totalCount ? $totalCount : 0,
                "pageIndex" => $pageIndex,
                "htmlData" => $html
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    //删除草稿箱
    function del_drafts(){
        $this->is_login();
        $id = isset($_REQUEST['draftsId']) ? trim($_REQUEST['draftsId']) : 0;
        $this->db->where(array("id"=>$id,"authorid"=>$this->bbs_userinfo['user_id']))->delete("bbs_article_drafts");
        $totalCount = $this->db->select("*")->from("bbs_article_drafts")->where(array("authorid"=>$user_id))->order_by("create_time desc")->get()->num_rows();
        $mess['reqStatus'] = true;
        $mess['totalCount'] = $totalCount;
        echo JSON($mess);exit;
    }
    
    //加载个人中心文章
    function get_arts_json(){
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
        $uuid = decrypt_user_id($uuid);
        $where = array();
        $is_self = $uuid == $this->bbs_userinfo['user_id'];
        
        $where['authorid'] = $uuid;
        $where['status'] = 1;
        $records_per_page = 10;
        $totalCount = $this->db->select("*")->from("bbs_article")->where($where)->get()->num_rows();
        $list = $this->db->select("a.id,a.title,a.authorid,a.summary,a.thumb,a.cat_id,a.tags_name,a.readnum,a.commentnum,a.status,a.create_time,c.name cat_name,u.nickname")->from("bbs_article a")
                ->join("bbs_article_category c","c.id = a.cat_id","left")
                ->join("users_info u","u.user_id = a.authorid","left")
                ->where($where)->order_by("create_time desc")->limit($records_per_page,$pageIndex * $records_per_page)->get()->result_array();
        $html = "";
        foreach ($list as $key=>$val){
            $user_id = encrypt_user_id($val['authorid']);
            $val['detail_url'] = $val['status'] == 1 ? web_url("p/".encrypt_article_id($val['id'])) : web_url("/p/upub/".encrypt_article_id($val['id']));
            $val['space_url'] = web_url("u/".$user_id);
            $val['create_time'] = date("Y-m-d H:i:s",$val['create_time']);
            $val['cat_url'] = web_url("p/cat-".$val['cat_id']);
            $tags_str = "";
            if($val['tags_name']){
                $tags_arr = explode(",", $val['tags_name']);
                foreach ($tags_arr as $v){
                    $v = explode("_", $v);
                    $tags_str .= "<a href='".web_url("p/tag-".$v[1])."' target='_blank'>$v[0]</a>";
                }
            }
            
            $edit_str = $is_self ? "<a href='".web_url("post/edit/".encrypt_article_id($val['id']))."' class='fr checked icon-index' title='编辑'></a>" : "";
            
            $html .= "<li class='article-con'>
                        <a href='$val[detail_url]' target='_blank' class='img fl'>
                                <img src='$val[thumb]'/>
                        </a>
                        <div class='con fr'>
                                <a href='$val[detail_url]' target='_blank' class='title'>$val[title]</a>$edit_str
                                <a href='$val[detail_url]' target='_blank' class='txt textnum110'>$val[summary]</a>
                                <div class='label mt10'>
                                        <div class='label-list'>".$tags_str."</div>
                                        <div class='clear'></div>
                                </div>
                                <div class='user mt15'>
                                		<b class='icon-index section fl mr5'></b>
                                        <a href='$val[cat_url]' target='_blank' class='fl cat'>$val[cat_name]</a>
                                        <a href='".($is_self ? "javascript:void(0);" : $val['space_url'])."' class='name fl ml15'>作者：".($is_self ? "我" : "Ta")."</a>
                                        <b class='icon-index eye fl ml15'></b>
                                        <span class='num fl ml5'>$val[readnum]/$val[commentnum]</span>
                                        <p class='time fr'>$val[create_time]</p>
                                        <div class='clear'></div>
                                </div>
                        </div>
                        <div class='clear'></div>
                    </li>";
            
        }
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "totalCount" => $totalCount ? $totalCount : 0,
                "pageIndex" => $pageIndex,
                "htmlData" => $html,
                "goto" => true
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    //个人文章收藏
    function get_arts_collect_json(){
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
        $uuid = decrypt_user_id($uuid);
        $where = array();
        $where['f.user_id'] = $uuid;
        $where['f.is_del'] = 1;
        $records_per_page = 10;
        $totalCount = $this->db->select("f.*")->from("bbs_favorite f")->where($where)->get()->num_rows();
        $list = $this->db->select("f.user_id,f.article_id,f.author_id,a.title,a.summary,a.thumb,a.cat_id,a.tags_name,a.readnum,a.commentnum,a.create_time,u.nickname")
                ->from("bbs_favorite f")
                ->join("bbs_article a","a.id = f.article_id","left")
                ->join("users_info u","u.user_id = f.author_id","left")
                ->where($where)->order_by("f.create_time desc")->limit($records_per_page,$pageIndex * $records_per_page)->get()->result_array();
        $html = "";
        foreach ($list as $key=>$val){
            $user_id = encrypt_user_id($val['author_id']);
            $val['detail_url'] = web_url("p/".encrypt_article_id($val['article_id']));
            $val['space_url'] = web_url("u/".$user_id);
            $val['create_time'] = date("Y-m-d H:i:s",$val['create_time']);
            $cat = $this->db->select("*")->from("bbs_article_category")->where(array("id"=>$val['cat_id']))->order_by("id desc")->get()->row_array();
            $val['cat_url'] = web_url("p/cat-".$val['cat_id']);
            $val['cat_name'] = $cat['name'];
            $tags_str = "";
            if($val['tags_name']){
                $tags_arr = explode(",", $val['tags_name']);
                foreach ($tags_arr as $v){
                    $v = explode("_", $v);
                    $tags_str .= "<a href='".web_url("p/tag-".$v[1])."' target='_blank'>$v[0]</a>";
                }
            }
            $html .= "<li class='article-con'>
                        <a href='$val[detail_url]' target='_blank' class='img fl'>
                                <img src='$val[thumb]'/>
                        </a>
                        <div class='con fr'>
                                <a href='$val[detail_url]' target='_blank' class='title'>$val[title]</a>
                                <a href='javascript:void(0);' class='collection fr' onclick='delete_favor_act(this);' data-favor-id='".encrypt_article_id($val['article_id'])."' data-val='1'>取消收藏</a>
                                <a href='$val[detail_url]' target='_blank' class='txt textnum110'>$val[summary]</a>
                                <div class='label mt10'>
                                        <div class='label-list'>".$tags_str."</div>
                                        <div class='clear'></div>
                                </div>
                                <div class='user mt15'>
                                		<b class='icon-index section fl mr5'></b>
                                        <a href='$val[cat_url]' target='_blank' class='fl cat'>$val[cat_name]</a>
                                        <a href='$val[space_url]' target='_blank' class='name fl ml15'>作者：$val[nickname]</a>
                                        <b class='icon-index eye fl ml15'></b>
                                        <span class='num fl ml5'>$val[readnum]/$val[commentnum]</span>
                                        <p class='time fr'>$val[create_time]</p>
                                        
                                </div>
                        </div>
                        <div class='clear'></div>
                    </li>";
            
        }
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "totalCount" => $totalCount ? $totalCount : 0,
                "pageIndex" => $pageIndex,
                "htmlData" => $html,
                "goto" => true
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    
    //添加、取消文章收藏
    function cancel_favor_act(){
        $this->is_login();
        if($_POST){
            $article_id = isset($_POST['collectId']) ? trim($_POST['collectId']) : 0;
            $article_id = decrypt_article_id($article_id);
            $is_favor = isset($_POST['is_favor']) ? trim($_POST['is_favor']) : 0;
            $art = $this->db->select("id,title,authorid")->from("bbs_article")->where(array("id"=>$article_id))->get()->row_array();
            if(!$art){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1001;
                $mess['errorMsg'] = "文章不存在或已被删除";
                echo JSON($mess);exit;
            }
            if($art['authorid'] == $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1001;
                $mess['errorMsg'] = "不能收藏自己的文章哦";
                echo JSON($mess);exit;
            }
            if($is_favor){//添加
                
                $status = $this->db->select("f.*")->from("bbs_favorite f")->where(array("f.user_id"=>$this->bbs_userinfo['user_id'],"f.article_id"=>$article_id,"f.is_del"=>0))->order_by("f.create_time desc")->get()->row_array();
                if($status){
                    $this->db->trans_begin();
                    $query1 = $this->db->query("update tan_bbs_favorite set is_del = 1 where user_id = ".$this->bbs_userinfo['user_id']." and article_id = ".$article_id);
                    $query2 = $this->db->query("update tan_bbs_count set favor_count = favor_count + 1 where user_id = ".$this->bbs_userinfo['user_id']);

                    if($query1 && $query2){
                        $this->db->trans_commit();
                        $mess['reqStatus'] = true;
                        echo JSON($mess);exit;
                    }else{
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);exit;
                    }
                }else{
                    $data = array();
                    $data['article_id'] = $article_id;
                    $data['user_id'] = $this->bbs_userinfo['user_id'];
                    $data['author_id'] = $art['authorid'];
                    $data['is_del'] = 1;
                    $data['create_time'] = time();
                    
                    $this->db->trans_begin();
                    $this->db->insert("bbs_favorite",$data);
                    $query1 = $this->db->affected_rows();
                    $query2 = $this->db->query("update tan_bbs_count set favor_count = favor_count + 1 where user_id = ".$this->bbs_userinfo['user_id']);
                    if($query1 && $query2){
                        $this->db->trans_commit();
                        //发送消息
                        $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$art['authorid'],"operator_id"=>$article_id,"event_type"=>"event_collect_article","type"=>"article","is_show"=>1));
                        
                        $mess['reqStatus'] = true;
                        echo JSON($mess);exit;
                    }else{
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);exit;
                    }
                    
                }
//                $behavior = $this->bbs_account_model->check_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$author_id,"event_type"=>"event_collect_article"));
//                if($behavior==null){
//                    //更新个人动态
//                    $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$author_id,"event_type"=>"event_collect_article","is_show"=>1));
//                }
                
            }else{//取消操作
                
                $status = $this->db->select("f.*")->from("bbs_favorite f")->where(array("f.user_id"=>$this->bbs_userinfo['user_id'],"f.article_id"=>$article_id))->order_by("f.create_time desc")->get()->row_array();
                if(!$status){
                    $mess['reqStatus'] = false;
                    $mess['errorCode'] = 1001;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);exit;
                }
                $this->db->trans_begin();
                $query1 = $this->db->query("update tan_bbs_favorite set is_del = 0 where user_id = ".$this->bbs_userinfo['user_id']." and article_id = ".$article_id);
                $query2 = $this->db->query("update tan_bbs_count set favor_count = favor_count - 1 where user_id = ".$this->bbs_userinfo['user_id']);
                
                if($query1 && $query2){
                    $this->db->trans_commit();
                    $mess['reqStatus'] = true;
                    echo JSON($mess);exit;
                }else{
                    $this->db->trans_rollback();
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);exit;
                }
            }
        }
    }
    //增加文章阅读数
    function art_read_num_add(){
        if($_GET){
            $article_id = isset($_GET['article_id']) ? trim($_GET['article_id']) : 0;
            $uuid = isset($_GET['uuid']) ? trim($_GET['uuid']) : 0;
            $article_id = decrypt_article_id($article_id);
            $uuid = decrypt_user_id($uuid);
            if($uuid == $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                echo JSON($mess);exit;
            }
            $article = $this->db->select("id,title,authorid,readnum")->from("bbs_article")->where(array("id"=>$article_id))->get()->row_array();
            if(!$article){
                $mess['reqStatus'] = false;
                echo JSON($mess);exit;
            }
            if($article['authorid'] == $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                echo JSON($mess);exit;
            }
            $this->db->trans_begin();
            $query = $this->db->query("update tan_bbs_article set readnum = readnum + 1 where id = ".$article_id);
            if($query){
                $this->db->trans_commit();
                
                $mess['reqStatus'] = true;
                $mess['readNum'] = $article['readnum'] + 1;
                echo JSON($mess);exit;
            }else{
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                echo JSON($mess);exit;
            }
        }
        
    }
    //文章点赞
    function art_like_num_add(){
        $this->is_login();
        if($_POST){
            $article_id = isset($_POST['article_id']) ? trim($_POST['article_id']) : 0;
            $article_id = decrypt_article_id($article_id);
            $article = $this->db->select("id,title,authorid,likes")->from("bbs_article")->where(array("id"=>$article_id))->get()->row_array();
            if(!$article){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "文章不存在或已被删除";
                echo JSON($mess);exit;
            }
            $flag = $this->db->select("*")->from("bbs_like")->where(array("user_id"=>$this->bbs_userinfo['user_id'],"article_id"=>$article_id))->order_by("create_time desc")->get()->num_rows();
            if($flag){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "已点赞";
                echo JSON($mess);exit;
            }
            
            $data = array();
            $data['article_id'] = $article_id;
            $data['user_id'] = $this->bbs_userinfo['user_id'];
            $data['create_time'] = time();
            $this->bbs_detail_model->insert_article_like($data);
            //发送消息
            $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$article['authorid'],"operator_id"=>$article_id,"event_type"=>"event_like_article","is_show"=>1,"type"=>"article"));
            
//            $behavior = $this->bbs_account_model->check_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$article_id,"event_type"=>"event_like_article"));
//            if($behavior==null){
//            //更新个人动态
//            $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$article_id,"event_type"=>"event_like_article","is_show"=>1));
//            }
            
            $errmes['reqStatus'] = true;
            echo JSON($errmes);exit;
        }
    }
    
    //关注作者
    function cancel_fan_act(){
        if($_POST){
            $this->is_login();
            $author_id = isset($_POST['author_id']) ? trim($_POST['author_id']) : 0;
            $author_id = decrypt_user_id($author_id);
            $is_fan = isset($_POST['is_fan']) ? trim($_POST['is_fan']) : 0;
            if($author_id == $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "不能关注自己哦";
                echo JSON($mess);exit;
            }
            if($is_fan){//添加
                $status = $this->db->select("f.*")->from("bbs_fans f")->where(array("f.followuid"=>$this->bbs_userinfo['user_id'],"f.user_id"=>$author_id,"f.is_del"=>0))->order_by("f.create_time desc")->get()->row_array();
                if($status){
                    $this->db->trans_begin();
                    $query1 = $this->db->query("update tan_bbs_fans set is_del = 1 where followuid = ".$this->bbs_userinfo['user_id']." and user_id = ".$author_id);
                    $query2 = $this->db->query("update tan_bbs_count set fans_count = fans_count + 1 where user_id = ".$author_id);
                    $query3 = $this->db->query("update tan_bbs_count set following_count = following_count + 1 where user_id = ".$this->bbs_userinfo['user_id']);

                    if($query1 && $query2 && $query3){
                        $this->db->trans_commit();
                        $mess['reqStatus'] = true;
                        echo JSON($mess);exit;
                    }else{
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);exit;
                    }
                }else{
                    $data = array();
                    $data['followuid'] = $this->bbs_userinfo['user_id'];
                    $data['user_id'] = $author_id;
                    $data['is_del'] = 1;
                    $data['create_time'] = time();
                    
                    $this->db->trans_begin();
                    $this->db->insert("bbs_fans",$data);
                    $query1 = $this->db->affected_rows();
                    $query2 = $this->db->query("update tan_bbs_count set fans_count = fans_count + 1 where user_id = ".$author_id);
                    $query3 = $this->db->query("update tan_bbs_count set following_count = following_count + 1 where user_id = ".$this->bbs_userinfo['user_id']);
                    if($query1 && $query2 && $query3){
                        $this->db->trans_commit();
                        
                        /**app推送**/
                        /*
                        $this->load->library('my_getui');
                        $msg_type = $this->web_config['user_focus'];
                        $push = array();
                        $push['type'] = $msg_type['user_focus'];
                        $push['title'] = "关注通知";
                        $push['content'] = "您收到一条好友关注通知";
                        $push['target_id'] = encrypt_user_id($this->bbs_userinfo['user_id']);
                        $Push = new My_getui();
                        $Push->pushMessageToSingle(encrypt_user_id($author_id),$push);*/
                        /****/
                        
                        //发送消息通知
                        $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$author_id,"operator_id"=>0,"event_type"=>"event_focus_author","is_show"=>1,"type"=>"system"));
                        //更新个人动态
                        //$this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$author_id,"event_type"=>"event_focus_author","is_show"=>1,"type"=>"system"));
                        
                        $mess['reqStatus'] = true;
                        echo JSON($mess);exit;
                    }else{
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);exit;
                    }
                    
                    
                }
                
            }else{//删除
                
                $status = $this->db->select("f.*")->from("bbs_fans f")->where(array("f.followuid"=>$this->bbs_userinfo['user_id'],"f.user_id"=>$author_id))->order_by("f.create_time desc")->get()->row_array();
                if(!$status){
                    $mess['reqStatus'] = false;
                    $mess['errorCode'] = 1001;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);exit;
                }
                $this->db->trans_begin();
                $query1 = $this->db->query("update tan_bbs_fans set is_del = 0 where id = ".$status['id']);
                $query2 = $this->db->query("update tan_bbs_count set following_count = following_count - 1 where user_id = ".$this->bbs_userinfo['user_id']);
                $query3 = $this->db->query("update tan_bbs_count set fans_count = fans_count - 1 where user_id = ".$author_id);
                
                if($query1 && $query2 && $query3){
                    $this->db->trans_commit();
                    $mess['reqStatus'] = true;
                    echo JSON($mess);exit;
                }else{
                    $this->db->trans_rollback();
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);exit;
                }
                
            }
        }
    }
    //显示用户的关注
    function  get_follows_json(){
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 1;
        $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
        $uuid = decrypt_user_id($uuid);
        $records_per_page = 8;
        $where['followuid'] = $uuid;
        $where['is_del'] = 1;
        $totalCount = $this->db->select("*")->from("bbs_fans")->where($where)->get()->num_rows();
        $list = $this->db->select("f.*,u.nickname,u.head_img")->from("bbs_fans f")
                ->join("users_info u","u.user_id = f.user_id","left")
                ->where($where)->order_by("create_time desc")->limit($records_per_page,($pageIndex -1) * $records_per_page)->get()->result_array();
        $html = "<ul style='display: block;'>";
        foreach ($list as $key=>$val){
            $user_id = encrypt_user_id($val['user_id']);
            $val['space_url'] = web_url("u/".$user_id);
            $html .= "<li >
                            <a href='$val[space_url]' target='_blank' class='img'>
                                    <img src='$val[head_img]'/>
                            </a><br />
                            <a href='$val[space_url]' target='_blank' class='name'>".  mb_strcut($val['nickname'], 0, 6, "utf-8")."..</a>
                        </li>";
        }
        $html .= "<div class='clear'></div></ul>";
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "totalCount" => $totalCount ? $totalCount : 0,
                "pageIndex" => $pageIndex,
                "htmlData" => $html
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    //显示用户的访客
    function get_visitors_json(){
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 1;
        $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
        $uuid = decrypt_user_id($uuid);
        $records_per_page = 8;
        $where['space_uid'] = $uuid;
//        $where['day'] = date("Ymd");
        
        $totalCount = $this->db->select("*")->from("bbs_visit_list")->where($where)->get()->num_rows();
        $list = $this->db->select("f.*,u.nickname,u.head_img")->from("bbs_visit_list f")
                ->join("users_info u","u.user_id = f.user_id","left")
                ->where($where)->order_by("f.create_time desc")->group_by("f.user_id")->limit($records_per_page,($pageIndex -1) * $records_per_page)->get()->result_array();
        $html = "<ul style='display: block;'>";
        foreach ($list as $key=>$val){
            $user_id = encrypt_user_id($val['user_id']);
            $val['space_url'] = web_url("u/".$user_id);
            $html .= "<li >
                            <a href='$val[space_url]' target='_blank' class='img'>
                                    <img src='$val[head_img]'/>
                            </a><br />
                            <a href='$val[space_url]' target='_blank' class='name'>".mb_strcut($val[nickname], 0, 6,"utf-8")."..</a>
                        </li>";
        }
        $html .= "<div class='clear'></div></ul>";
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "totalCount" => $totalCount ? $totalCount : 0,
                "pageIndex" => $pageIndex,
                "htmlData" => $html
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    
    //添加文章评论
    function comment_add(){
        $this->is_login();
        if($_POST){
            $article_id = isset($_REQUEST['article_id']) ? trim($_REQUEST['article_id']) : 0;//文章id
            $content = isset($_REQUEST['content']) ? trim($_REQUEST['content']) : "";//评论内容
            $author_id = isset($_REQUEST['author_id']) ? trim($_REQUEST['author_id']) : 0;//文章作者
            $comment_id = isset($_REQUEST['comment_id']) ? trim($_REQUEST['comment_id']) : 0;//回复的评论id
            $comment_uid = isset($_REQUEST['comment_uid']) ? trim($_REQUEST['comment_uid']) : 0;//回复的评论者
            $card_index = isset($_REQUEST['card']) ? trim($_REQUEST['card']) : 0;//回复的卡通图片
            
            $article_id = decrypt_article_id($article_id);
            $author_id = decrypt_user_id($author_id);
            $comment_id = $comment_id ? decrypt_comment_id($comment_id) : 0;
            $comment_uid = $comment_uid ? decrypt_user_id($comment_uid) : 0;
            //获取文章
            $article = $this->db->select("id,authorid,status")->from("bbs_article")->where(array("id"=>$article_id))->order_by("create_time desc")->get()->row_array();
            
            if(!$article){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "文章不存在或已被删除，无法评论哦";
                echo JSON($mess);exit;
            }
            if($article['authorid'] != $author_id){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            if($comment_id){//获取评论
                $comment = $this->db->select("id,uid,content")->from("bbs_article_comment")->where(array("id"=>$comment_id,"is_show"=>1))->order_by("create_time desc")->get()->row_array();
                if(!$comment){
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "此评论不存在或已删除，无法回复哦";
                    echo JSON($mess);exit;
                }
                //如果前台获取的回复评论作者不等于真实评论作者，则视为非法操作
                if($comment['uid'] != $comment_uid){
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);exit;
                }
            }
            
            if(strip_tags(trim($content)) == ""){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "回复内容不能为空！";
                echo JSON($mess);exit;
            }
            
            $is_self = $author_id == $this->bbs_userinfo['user_id'];
            
            $data = array();
            $data["uid"] = $this->bbs_userinfo['user_id'];
            $data["article_id"] = $article_id;
            $data["authorid"] = $author_id;
            $data["content"] = strip_tags($content);
            $data["create_time"] = time();
            $data["month"] = date("Ym");
            $data["day"] = date("Ymd");
            $data["repay_user_id"] = $comment_uid ? $comment_uid : 0;
            $data["cid"] = $comment_id ? $comment_id : 0;
            $data["type"] = $comment_id ? 1 : 0;
            $data["card_index"] = $card_index;
            
            $this->db->trans_begin();
            $this->db->insert("bbs_article_comment",$data);
            $insert_id = $this->db->insert_id();
//            $query1 = $this->db->query("update tan_bbs_count set reply_count = reply_count + 1 where user_id = ".$this->bbs_userinfo['user_id']);
            $query2 = $this->db->query("update tan_bbs_article set commentnum = commentnum + 1 where id = ".$article_id);
            
//            if($comment_uid){
//                $query3 = $this->db->query("update tan_bbs_count set reply_count = reply_count + 1 where user_id = ".$comment_uid);
//            }else{
//                $query3 = true;
//            }
            
            if($insert_id && $query2){
                $this->db->trans_commit();
                
                //发送消息通知
                if($comment_id){
                    //回复评论
                    $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$comment_uid,"operator_id"=>$insert_id,"event_type"=>"event_comment_article","type"=>"article","is_show"=>1));
                }else{
                    //评论文章
                    if(!$is_self){
                        $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$author_id,"operator_id"=>$insert_id,"event_type"=>"event_reply_article","type"=>"article","is_show"=>1));
                    }
                }
                
//                //更新个人动态
//                $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$result,"event_type"=>"event_comment_article","is_show"=>1));
                $mess['reqStatus'] = true;
                $mess['comment_url'] = web_url("p/".encrypt_article_id($article_id)."/comments/".  encrypt_comment_id($insert_id));
                echo JSON($mess);exit;
                
            }else{
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);exit;
            }
        }
    }
    
    //显示文章评论信息
    function get_comments_json(){
        if($_POST){
            $article_id = isset($_REQUEST['article_id']) ? trim($_REQUEST['article_id']) : 0;//文章id
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : "";//显示当前页
            $comment_id = isset($_REQUEST['comment_id']) ? trim($_REQUEST['comment_id']) : 0;//评论id
            $goto = isset($_REQUEST['goto']) ? trim($_REQUEST['goto']) : false;//是否跳转到知道评论
            $article_id = decrypt_article_id($article_id);
            $comment_id = $comment_id ? decrypt_comment_id($comment_id) : 0;
            //每页显示数量
            $records_per_page = 30;
            $is_goto = false;
            //获取文章
            $article = $this->db->select("id,authorid,status")->from("bbs_article")->where(array("id"=>$article_id))->order_by("create_time desc")->get()->row_array();
            if(!$article){
                $result = array(
                    "reqStatus" => true,
                    "data" => array("totalCount" => 0,"pageIndex" => $pageIndex,"htmlData" => "","goto" => false,"isGoto"=>$is_goto,"totalPage"=>0,"targetId"=>0)
                );
                echo json_encode($result,JSON_HEX_TAG);die;
            }
            //总评论数
            $totalCount = $this->db->select("*")->from("bbs_article_comment")->where(array("article_id"=>$article_id,"is_show"=>1))->order_by("id desc")->get()->num_rows();
            //总页数
            $totalPage = ceil($totalCount/$records_per_page);
            
            if($goto){//跳转到指定评论
                $comment = $this->db->select("*")->from("bbs_article_comment")->where(array("id"=>$comment_id,"is_show"=>1))->order_by("create_time desc")->get()->row_array();
                if($comment){
                    $where = array();
                    $where['article_id'] = $comment['article_id'];
                    $where['is_show'] = 1;
                    $where['id <='] = $comment['id'];
                    //获取评论总条数
                    $comment_totalCount = $this->db->select("*")->from("bbs_article_comment")->where($where)->order_by("id asc")->get()->num_rows();
                    //计算当前评论所处的哪一页
                    $pageIndex = intval(($comment_totalCount/$records_per_page)) == 0 ? intval(($comment_totalCount/$records_per_page)) : ceil($comment_totalCount/$records_per_page);
                    $where = array();
                    $where['c.article_id'] = $comment['article_id'];
                    $where['c.is_show'] = 1;
                    $is_goto = true;
                    $comment_id = encrypt_comment_id($comment_id);
                }else{
                    $where = array();
                    $where['c.article_id'] = $article_id;
                    $where['c.is_show'] = 1;
                    $comment_id = 0;
                }
                
            }else{
                $where = array();
                $where['c.article_id'] = $article_id;
                $where['c.is_show'] = 1;
                $comment_id = 0;
            }
            $list = $this->db->select("c.*,u1.nickname comment_nickname,u1.head_img comment_head_img,u2.nickname reply_nickname,u2.head_img reply_head_img")
                        ->from("bbs_article_comment c")
                        ->join("users_info u1","u1.user_id = c.uid","left")
                        ->join("users_info u2","u2.user_id = c.repay_user_id","left")
                        ->where($where)->order_by("id asc")->limit($records_per_page,$pageIndex * $records_per_page)->get()->result_array();
            
            $html = $this->set_comment_str($list,$pageIndex*$records_per_page);
            
            $result = array(
                    "reqStatus" => true,
                    "data" => array("totalCount" => $totalCount,"pageIndex" => $pageIndex,"htmlData" => $html,"goto" => false,"isGoto"=>$is_goto,"totalPage"=>$totalPage,"targetId"=>$comment_id )
                );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }
    //显示视频评论信息
    function get_video_comments_json(){
        if($_POST){
            $video_id = isset($_REQUEST['vid']) ? trim($_REQUEST['vid']) : 0;//视频id
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : "";//显示当前页
            $comment_id = isset($_REQUEST['comment_id']) ? trim($_REQUEST['comment_id']) : 0;//评论id
            $goto = isset($_REQUEST['goto']) ? trim($_REQUEST['goto']) : false;//是否跳转到知道评论
            $video_id = decrypt_video_id($video_id);
            $comment_id = $comment_id ? decrypt_comment_id($comment_id) : 0;
            //每页显示数量
            $records_per_page = 30;
            $is_goto = false;
            //获取视频
            $video = $this->db->select("id,authorid,status,salt")->from("video")->where(array("id"=>$video_id))->order_by("create_time desc")->get()->row_array();
            if(!$video){
                $result = array(
                    "reqStatus" => true,
                    "data" => array("totalCount" => 0,"pageIndex" => $pageIndex,"htmlData" => "","goto" => false,"isGoto"=>$is_goto,"totalPage"=>0,"targetId"=>0)
                );
                echo json_encode($result,JSON_HEX_TAG);die;
            }
            //总评论数
            $totalCount = $this->db->select("*")->from("video_comment")->where(array("video_id"=>$video_id,"is_show"=>1))->order_by("id desc")->get()->num_rows();
            //总页数
            $totalPage = ceil($totalCount/$records_per_page);
            
            if($goto){//跳转到指定评论
                $comment = $this->db->select("*")->from("video_comment")->where(array("id"=>$comment_id,"is_show"=>1))->order_by("create_time desc")->get()->row_array();
                if($comment){
                    $where = array();
                    $where['video_id'] = $comment['video_id'];
                    $where['is_show'] = 1;
                    $where['id <='] = $comment['id'];
                    //获取评论总条数
                    $comment_totalCount = $this->db->select("*")->from("video_comment")->where($where)->order_by("id asc")->get()->num_rows();
                    //计算当前评论所处的哪一页
                    $pageIndex = intval(($comment_totalCount/$records_per_page)) == 0 ? intval(($comment_totalCount/$records_per_page)) : ceil($comment_totalCount/$records_per_page);
                    $where = array();
                    $where['c.video_id'] = $comment['video_id'];
                    $where['c.is_show'] = 1;
                    $is_goto = true;
                    $comment_id = encrypt_comment_id($comment_id);
                }else{
                    $where = array();
                    $where['c.video_id'] = $video_id;
                    $where['c.is_show'] = 1;
                    $comment_id = 0;
                }
                
            }else{
                $where = array();
                $where['c.video_id'] = $video_id;
                $where['c.is_show'] = 1;
                $comment_id = 0;
            }
            $list = $this->db->select("c.*,u1.nickname comment_nickname,u1.head_img comment_head_img,u2.nickname reply_nickname,u2.head_img reply_head_img")
                        ->from("video_comment c")
                        ->join("users_info u1","u1.user_id = c.uid","left")
                        ->join("users_info u2","u2.user_id = c.repay_user_id","left")
                        ->where($where)->order_by("c.id desc")->limit($records_per_page,$pageIndex * $records_per_page)->get()->result_array();
            
            $html = $this->set_video_comment_str($video,$list,$pageIndex*$records_per_page);
            
            $result = array(
                    "reqStatus" => true,
                    "data" => array("totalCount" => $totalCount,"pageIndex" => $pageIndex,"htmlData" => $html,"goto" => false,"isGoto"=>$is_goto,"totalPage"=>$totalPage,"targetId"=>$comment_id )
                );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }
    //显示空间内评论信息
    function get_comment_json(){
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
        $uuid = decrypt_user_id($uuid);
        $where = array();
        $where['uid'] = $uuid;
        $where['is_show'] = 1;
        $is_self = $uuid == $this->bbs_userinfo['user_id'];
        $records_per_page = 10;
        $totalCount = $this->db->select("*")->from("bbs_article_comment")->where($where)->get()->num_rows();
        $list = $this->db->select("c.*,a.title,a.commentnum,u1.nickname authorid_nickname,u1.head_img authorid_head_img,u2.nickname reply_nickname")
                ->from("bbs_article_comment c")
                ->join("users_info u1","u1.user_id = c.authorid","left")
                ->join("users_info u2","u2.user_id = c.repay_user_id","left")
                ->join("bbs_article a","a.id = c.article_id","left")
                ->where($where)->order_by("id desc")->limit($records_per_page,$pageIndex * $records_per_page)->get()->result_array();
        $html = "";
        foreach ($list as $key=>$val){
            $authorid = encrypt_user_id($val['authorid']);
            $val['comment_url'] = web_url("p/".encrypt_article_id($val['article_id'])."/comments/".encrypt_comment_id($val['id']));
            $html .= "<li>
                        <a href='".web_url("u/".$authorid)."' target='_blank' class='head fl mr20'><img src='$val[authorid_head_img]' onerror='this.onerror=null;this.src='http://static.tan66.com/upfiles/head.png';'/></a>
                        <div class='con'>
                                <div class='overhide'>
                                    <a href='$val[comment_url]' target='_blank' class='title fl'>$val[title]</a>
                                        <i class='time fr'>".date("Y-m-d H:i:s",$val['create_time'])."</i>
                                </div>
                                <div class='mt10'>
                                    <i>作者：</i><a href='".web_url("u/".$authorid)."' target='_blank' class='name mr20'>$val[authorid_nickname]</a>
                                        <i class='num'>$val[commentnum]评论</i>
                                        <div class='btn fr'>".($is_self ? "<a href='javascript:void(0);' class='del' onclick='delete_comment_act({comment_id:".encrypt_comment_id($val['id']).",obj:this});'>删除</a>" : "<a href='".$val['comment_url']."' target='_blank' class='rep ml20'>回复</a>")."</div>
                                        <div class='clear'></div>
                                </div>
                        </div>
                        <div class='txt'>".($val['repay_user_id'] ? "<span><a href='".web_url("u/".encrypt_user_id($val['repay_user_id']))."' style='font-size: 12px;color: #44A7E4;' target='_blank'>@".$val['reply_nickname']."：</a></span>" : "")."<a href='$val[comment_url]' target='_blank'>".  mb_strcut(strip_tags($val[content]), 0, 150, "utf-8")."</a></div>
                    </li>";
        }
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "totalCount" => $totalCount ? $totalCount : 0,
                "pageIndex" => $pageIndex,
                "htmlData" => $html,
                "goto" => true
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    
    //删除文章评论
    function cancel_comment_act(){
        $this->is_login();
        if($_POST){
            $comment_id = isset($_POST['comment_id']) ? trim($_POST['comment_id']) : 0;
            $comment_id = decrypt_comment_id($comment_id);
            $comment = $this->db->select("*")->from("bbs_article_comment")->where(array("id"=>$comment_id,"is_show"=>1))->order_by("id desc")->get()->row_array();
            if(!$comment){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "评论已删除或不存在";
                echo JSON($mess);exit;
            }
            
            if($comment['uid'] != $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            
            $this->db->trans_begin();
            $query1 = $this->db->query("update tan_bbs_article_comment set is_show = 0 where id = ".$comment_id);
            $query2 = $this->db->query("update tan_bbs_article set commentnum = commentnum - 1 where id = ".$comment['article_id']);
            if($query1 && $query2){
                $this->db->trans_commit();
                $mess['reqStatus'] = true;
                echo JSON($mess);exit;
            }else{
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);exit;
            }
        }
    }
    //删除视频评论
    function cancel_video_comment_act(){
        $this->is_login();
        if($_POST){
            $comment_id = isset($_POST['comment_id']) ? trim($_POST['comment_id']) : 0;
            $comment_id = decrypt_comment_id($comment_id);
            $comment = $this->db->select("*")->from("video_comment")->where(array("id"=>$comment_id,"is_show"=>1))->order_by("id desc")->get()->row_array();
            if(!$comment){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "评论已删除或不存在";
                echo JSON($mess);exit;
            }
            
            if($comment['uid'] != $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            
            $this->db->trans_begin();
            $userid = $this->bbs_userinfo['user_id'];
            $query1 = $this->db->query("update tan_video_comment set is_show = 0 where id = ".$comment_id);
            $query2 = $this->db->query("update tan_video set commentnum = commentnum - 1 where id = ".$comment['video_id']);
            if($query1 && $query2){
                $this->db->trans_commit();
                $mess['reqStatus'] = true;
                echo JSON($mess);exit;
            }else{
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);exit;
            }
        }
    }
    //显示私信列表
    function get_letter_json(){
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 1;
        $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
        $uuid = decrypt_user_id($uuid);
        $records_per_page = 10;
        $where['space_uid'] = $uuid;
        //获取私信列表总数
        $totalCount = $this->db->select('*')->from("bbs_user_dialog_room")->where(array("dialog_from"=>$uuid,"is_del"=>0))->get()->num_rows();
        $sql = "SELECT * FROM (SELECT room_name,content,create_time FROM tan_bbs_user_dialog_message WHERE ((sender_from_id=$uuid) OR (sender_to_id=$uuid AND is_show=0)) and room_name not in (select room_name from tan_bbs_user_dialog_room where dialog_from = $uuid and is_del = 1) ORDER BY create_time DESC) a GROUP BY room_name ORDER BY `a`.`create_time` DESC limit ".($pageIndex * $records_per_page).",$records_per_page";
        $list = $list = $this->db->query($sql)->result_array();
        $html = "";
        foreach ($list as $key=>$val){
            $room_info = $this->db->select("r.*,u.nickname,u.head_img,u1.salt")
                    ->from("bbs_user_dialog_room r")
                    ->join("users_info u","u.user_id = r.dialog_from")
                    ->join("users u1","u1.user_id = r.dialog_from")
                    ->where(array("room_name"=>$val['room_name'],"dialog_to"=>$uuid))->order_by("id desc")->get()->row_array();
            //获取未读消息
            $no_read = $this->db->select('*')->from("bbs_user_dialog_message")->where(array("sender_to_id"=>$uuid,"room_name"=>$room_info['room_name'],"is_read"=>0,"is_show"=>0))->get()->num_rows();
            $no_read ? ($no_read > 99 ? "99+" : $no_read) : 0;
            
            $dialog_from_id = encrypt_user_id($room_info['dialog_from']);
            $html .= "<li>
                        <div class='p20'>
                            <div class='head fl mr20'>
                                <a href='".web_url("u/".$dialog_from_id)."' class='header'><img src='$room_info[head_img]' onerror=\"this.onerror=null;this.src='http://static.tan66.com/upfiles/head.png';\"/></a>
                                <b ".($room_info['is_show'] ? "class='on'" : "").">".($room_info['is_show'] ? "" : ($no_read ? $no_read : ""))."</b>
                            </div>
                            <div class='box fl'>
                                <a href='".web_url("chats/".$room_info['salt'])."' style='display: block;position: absolute;width: 750px;height: 49px;'></a>
                                <div>
                                    <a href='".web_url("u/".$dialog_from_id)."' class='name fl'>$room_info[nickname]</a>
                                    <div class='arrow-box fr'>
                                        <a href='javasript:void(0);' class='icon-com icon-arrow'></a>
                                        <div class='arrow-hide'>
                                            <div class='ah-div'></div>
                                            <a href='".web_url("chats/".$room_info['salt'])."'>私信</a>
                                            <a href='javascript:void(0);' class='shield-dialog' onclick=\"shield_dialog_fn({dialog_room:'$room_info[room_name]',obj:this,dialog_user:'$room_info[nickname]'});\" data-value='$room_info[is_show]'>".($room_info['is_show'] ? "已屏蔽" : "屏蔽")."</a>
                                            <a href='javascript:void(0);' onclick=\"cancel_dialog_fn({dialog_room:'$room_info[room_name]',dialog_user:'$room_info[nickname]'});\">删除</a>
                                        </div>
                                    </div>
                                    <div class='clear'></div>
                                </div>
                                <div class='overhide mt10'>
                                    <p class='txt fl'>".mb_strcut($val[content],0,200,"utf-8")."</p>
                                    <p class='time fr'>".date("Y-m-d H:i",$val['create_time'])."</p>
                                </div>
                                <div class='clear'></div>
                            </div>
                            <div class='clear'></div>
                        </div>
                    </li>";
        }
        
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "totalCount" => $totalCount ? $totalCount : 0,
                "pageIndex" => $pageIndex,
                "htmlData" => $html,
                "goto" => true
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    
    //删除私信对话
    function cancel_dialog_act(){
        $this->is_login();
        if($_POST){
            $dialog_room = isset($_POST['dialog_room']) ? trim($_POST['dialog_room']) : "";
            $uuid = isset($_POST['uuid']) ? trim($_POST['uuid']) : "";
            $uuid = decrypt_user_id($uuid);
            $room = $this->db->select("*")->from("bbs_user_dialog_room")->where(array("room_name"=>$dialog_room,"dialog_from"=>$uuid))->order_by("id desc")->get()->row_array();
            if(!$room){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法访问";
                echo JSON($mess);exit;
            }
            
            if($room['dialog_from'] != $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            
            $this->db->trans_begin();
            $query1 = $this->db->query("update tan_bbs_user_dialog_room set is_del = 1 where id = ".$room['id']);
            if($query1){
                $this->db->trans_commit();
                $mess['reqStatus'] = true;
                echo JSON($mess);exit;
            }else{
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);exit;
            }
        }
    }
    //屏蔽私信对话
    function shield_dialog_act(){
        $this->is_login();
        if($_POST){
            $dialog_room = isset($_POST['dialog_room']) ? trim($_POST['dialog_room']) : "";
            $uuid = isset($_POST['uuid']) ? trim($_POST['uuid']) : "";
            $value = isset($_POST['value']) ? trim($_POST['value']) : 0;
            $uuid = decrypt_user_id($uuid);
            $room = $this->db->select("*")->from("bbs_user_dialog_room")->where(array("room_name"=>$dialog_room,"dialog_to"=>$uuid))->order_by("id desc")->get()->row_array();
            if(!$room){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法访问";
                echo JSON($mess);exit;
            }
            
            if($room['dialog_to'] != $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            
            $this->db->trans_begin();
            $query1 = $this->db->query("update tan_bbs_user_dialog_room set is_show = $value where id = ".$room['id']);
            if($query1){
                $this->db->trans_commit();
                $mess['reqStatus'] = true;
                echo JSON($mess);exit;
            }else{
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);exit;
            }
        }
    }
    
    //修改或增加问题回答
    function ajax_modify_answer(){
        $this->is_login();
        if($_POST){
            $wendaId = isset($_POST['wendaId']) ? trim($_POST['wendaId']) : 0;//问答id
            $answerContent = isset($_POST['answerContent']) ? trim($_POST['answerContent']) : "";//回答内容
            $answerId = isset($_POST['answerId']) ? trim($_POST['answerId']) : 0;//回答id
            $type = isset($_POST['type']) ? trim($_POST['type']) : 0;//回答id
            if(!$type){//修改答案
                if($answerId){
                    $answerId = decrypt_answer_id($answerId);
                    $answer = $this->db->select("*")->from("bbs_wenda_answer")->where(array("id"=>$answerId,"user_id"=>$this->bbs_userinfo['user_id']))->order_by("id desc")->get()->row_array();
                    if(!$answer){
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "非法操作";
                        echo JSON($mess);exit;
                    }
                }
            }
            
            if($answerContent == ""){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "提交的回答不能为空哦";
                echo JSON($mess);exit;
            }
            $wendaId = decrypt_wenda_id($wendaId);
            $wenda =  $this->db->select("id,questioner_id,is_email_noitce,answer_id")->from("bbs_wenda")->where(array("id"=>$wendaId))->order_by("id desc")->get()->row_array();
            if(!$wenda){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            
            if($wenda['questioner_id'] == $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "不能自己给自己作答哦";
                echo JSON($mess);exit;
            }
            
            $allergicWord = file_get_contents("http://static.tan66.com/upfiles/files/badwords.txt");
            $allergicWord = str_replace(array("\r\n", "\r", "\n"),'',$allergicWord);
            $allergicWord= explode('|',$allergicWord);
            $info=0;
            for ($i=0;$i<count($allergicWord);$i++){  
                $check = substr_count($answerContent, $allergicWord[$i]);
                if($check>0){
                    $info = $check;
                    break;
                }
            }  
            if($info>0){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "检查您的回答内容里面有非法或敏感内容，请修正";
                echo JSON($mess);exit;
            }
            
            preg_match_all("/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.bmp|\.jpeg]))[\'|\"].*?[\/]?>/i", $answerContent, $matches);
            $thumb = $matches[1][0] ? $matches[1][0] : "";
            if($thumb){
                $result = $this->crypt->POST_Api("http://static.tan66.com/mimage/resize/150/100",array("file"=>$thumb));
                $result = json_decode($result,true);
                $thumb = $result['filename'];
            }else{
                $thumb = "";
            }
            
            $data = array();
            $data['user_id'] = $this->bbs_userinfo['user_id'];
            $data['wenda_id'] = $wendaId;
            $data['wenda_uid'] = $wenda['questioner_id'];
            $data['thumb'] = $thumb;
            $data['content'] = strip_tags($answerContent, "<br><img><p><div><a>");
            
            if(!$type){//修改回答
                $this->db->trans_begin();
                $query = $this->db->where(array("id"=>$answerId))->update("bbs_wenda_answer",$data);
                if($query){
                    $this->db->trans_commit();
                    $mess['reqStatus'] = true;
                    echo JSON($mess);exit;
                }else{
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);exit;
                }
                
            }else{//增加回答]
                $data['create_time'] = time();
                
                $this->db->trans_begin();
                $this->db->insert("bbs_wenda_answer",$data);
                $insert_id = $this->db->insert_id();
                $query1 = $this->db->query("update tan_bbs_wenda set answernum = answernum + 1 where id = ".$wendaId);
                $query2 = $this->db->query("update tan_bbs_count set answer_count = answer_count + 1 where user_id = ".$this->bbs_userinfo['user_id']);
                if($insert_id && $query1 && $query2){
                    $this->db->trans_commit();
                    //发送通知
                    //1、向问题发表者发送新答案通知
                    $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$wenda['questioner_id'],"operator_id"=>$insert_id,"event_type"=>"event_comment_wenda","is_show"=>1,"type"=>"wenda"));
                    //2、向关注此问题的所有人发送新答案通知
                    if(!$wenda['answer_id']){//问题还未被采纳
                        $datas = array();
                       //获取关注问答的人
                        $cares = $this->db->query("SELECT user_id FROM `tan_bbs_wenda_care` where wenda_id = $wendaId and is_del = 1 order by id desc")->result_array();
                        if($cares){
                            foreach ($cares as $val){
                                if($val['user_id'] == $this->bbs_userinfo['user_id']){
                                    continue;
                                }
                                $data = array();
                                $data['user_id'] = 0;
                                $data['recieve_id'] = $val['user_id'];
                                $data['operator_id'] = $insert_id;
                                $data['event_type'] = "event_comment_wenda_care";
                                $data['type'] = "wenda";
                                $data['is_show'] = 0;
                                $data['create_time'] = time();
                                $datas[] = $data; 
                            }
                            $this->db->insert_batch("bbs_notice",$datas);
                        }
                    }
                    $mess['reqStatus'] = true;
                    echo JSON($mess);exit;
                }else{
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);exit;
                }
            }
            
        }
    }
    //修改或增加曝光台回答
    function ajax_modify_exposure_answer(){
        $this->is_login();
        if($_POST){
            $wendaId = isset($_POST['wendaId']) ? trim($_POST['wendaId']) : 0;//问答id
            $answerContent = isset($_POST['answerContent']) ? trim($_POST['answerContent']) : "";//回答内容
            $answerId = isset($_POST['answerId']) ? trim($_POST['answerId']) : 0;//回答id
            $type = isset($_POST['type']) ? trim($_POST['type']) : 0;//回答id
            if(!$type){//修改答案
                if($answerId){
                    $answerId = decrypt_answer_id($answerId);
                    $answer = $this->db->select("*")->from("bbs_exposure_answer")->where(array("id"=>$answerId,"user_id"=>$this->bbs_userinfo['user_id']))->order_by("id desc")->get()->row_array();
                    if(!$answer){
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "非法操作";
                        echo JSON($mess);exit;
                    }
                }
            }

            if($answerContent == ""){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "提交的回答不能为空哦";
                echo JSON($mess);exit;
            }
            $wendaId = decrypt_wenda_id($wendaId);
            $wenda =  $this->db->select("id,questioner_id,is_email_noitce,answer_id")->from("bbs_exposure")->where(array("id"=>$wendaId))->order_by("id desc")->get()->row_array();
            if(!$wenda){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }

            if($wenda['questioner_id'] == $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "不能自己给自己作答哦";
                echo JSON($mess);exit;
            }

            $allergicWord = file_get_contents("http://static.tan66.com/upfiles/files/badwords.txt");
            $allergicWord = str_replace(array("\r\n", "\r", "\n"),'',$allergicWord);
            $allergicWord= explode('|',$allergicWord);
            $info=0;
            for ($i=0;$i<count($allergicWord);$i++){
                $check = substr_count($answerContent, $allergicWord[$i]);
                if($check>0){
                    $info = $check;
                    break;
                }
            }
            if($info>0){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "检查您的回答内容里面有非法或敏感内容，请修正";
                echo JSON($mess);exit;
            }

            preg_match_all("/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.bmp|\.jpeg]))[\'|\"].*?[\/]?>/i", $answerContent, $matches);
            $thumb = $matches[1][0] ? $matches[1][0] : "";
            if($thumb){
                $result = $this->crypt->POST_Api("http://static.tan66.com/mimage/resize/150/100",array("file"=>$thumb));
                $result = json_decode($result,true);
                $thumb = $result['filename'];
            }else{
                $thumb = "";
            }

            $data = array();
            $data['user_id'] = $this->bbs_userinfo['user_id'];
            $data['wenda_id'] = $wendaId;
            $data['wenda_uid'] = $wenda['questioner_id'];
            $data['thumb'] = $thumb;
            $data['content'] = strip_tags($answerContent, "<br><img><p><div><a>");

            if(!$type){//修改回答
                $this->db->trans_begin();
                $query = $this->db->where(array("id"=>$answerId))->update("bbs_exposure_answer",$data);
                if($query){
                    $this->db->trans_commit();
                    $mess['reqStatus'] = true;
                    echo JSON($mess);exit;
                }else{
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);exit;
                }

            }else{//增加回答]
                $data['create_time'] = time();

                $this->db->trans_begin();
                $this->db->insert("bbs_exposure_answer",$data);
                $insert_id = $this->db->insert_id();
                $query1 = $this->db->query("update tan_bbs_wenda set answernum = answernum + 1 where id = ".$wendaId);
                $query2 = $this->db->query("update tan_bbs_count set answer_count = answer_count + 1 where user_id = ".$this->bbs_userinfo['user_id']);
                if($insert_id && $query1 && $query2){
                    $this->db->trans_commit();
                    //发送通知
                    //1、向问题发表者发送新答案通知
                    $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$wenda['questioner_id'],"operator_id"=>$insert_id,"event_type"=>"event_comment_wenda","is_show"=>1,"type"=>"wenda"));
                    //2、向关注此问题的所有人发送新答案通知
                    if(!$wenda['answer_id']){//问题还未被采纳
                        $datas = array();
                        //获取关注问答的人
                        $cares = $this->db->query("SELECT user_id FROM `tan_bbs_exposure_care` where wenda_id = $wendaId and is_del = 1 order by id desc")->result_array();
                        if($cares){
                            foreach ($cares as $val){
                                if($val['user_id'] == $this->bbs_userinfo['user_id']){
                                    continue;
                                }
                                $data = array();
                                $data['user_id'] = 0;
                                $data['recieve_id'] = $val['user_id'];
                                $data['operator_id'] = $insert_id;
                                $data['event_type'] = "event_comment_wenda_care";
                                $data['type'] = "wenda";
                                $data['is_show'] = 0;
                                $data['create_time'] = time();
                                $datas[] = $data;
                            }
                            $this->db->insert_batch("bbs_notice",$datas);
                        }
                    }
                    $mess['reqStatus'] = true;
                    echo JSON($mess);exit;
                }else{
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);exit;
                }
            }

        }
    }
    //增加问答评论
    function ajax_add_reply(){
    $this->is_login();
    if($_POST){
        $answerId = isset($_POST['answerId']) ? trim($_POST['answerId']) : 0;//回答id
        $replyTxt = isset($_POST['replyTxt']) ? trim($_POST['replyTxt']) : "";//评论内容
        $replyId = isset($_POST['replyId']) ? trim($_POST['replyId']) : 0;//评论id
        $answerId = decrypt_answer_id($answerId);
        $replyId = $replyId ? decrypt_answer_reply_id($replyId) : 0;

        $answer = $this->db->select("*")->from("bbs_wenda_answer")->where(array("id"=>$answerId,"is_show"=>1))->order_by("id asc")->get()->row_array();
        if(!$answer){
            $mess['reqStatus'] = false;
            $mess['errorMsg'] = "非法操作";
            echo JSON($mess);exit;
        }

        if($replyId){
            $reply = $this->db->select("*")->from("bbs_wenda_reply")->where(array("id"=>$replyId,"answer_id"=>$answerId,"is_show"=>1))->order_by("id asc")->get()->row_array();
            if(!$reply){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
        }
        $allergicWord = file_get_contents("http://static.tan66.com/upfiles/files/badwords.txt");
        $allergicWord = str_replace(array("\r\n", "\r", "\n"),'',$allergicWord);
        $allergicWord= explode('|',$allergicWord);
        $info=0;
        for ($i=0;$i<count($allergicWord);$i++){
            $check = substr_count($replyTxt, $allergicWord[$i]);
            if($check>0){
                $info = $check;
                break;
            }
        }
        if($info>0){
            $mess['reqStatus'] = false;
            $mess['errorMsg'] = "检查您的评论内容里面有非法或敏感内容，请修正";
            echo JSON($mess);exit;
        }

        $data = array();
        $data['user_id'] = $this->bbs_userinfo['user_id'];
        $data['answer_id'] = $answerId;
        $data['answer_uid'] = $answer['user_id'];
        $data['wenda_id'] = $answer['wenda_id'];
        $data['wenda_uid'] = $answer['wenda_uid'];
        $data['content'] = $replyTxt;
        $data['create_time'] = time();
        $data['reply_id'] = $reply ? $reply['id'] : 0;
        $data['reply_uid'] = $reply ? $reply['user_id'] : 0;
        $data['is_show'] = 1;

        $this->db->trans_begin();
        $this->db->insert("bbs_wenda_reply",$data);
        $insert_id = $this->db->insert_id();
        $query1 = $this->db->query("update tan_bbs_wenda_answer set commentnum = commentnum + 1 where id = ".$answerId);
        if($insert_id && $query1){
            $this->db->trans_commit();

            //发送消息
            if($reply){
                if($reply['user_id'] != $this->bbs_userinfo['user_id']){
                    $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$reply['user_id'],"operator_id"=>$insert_id,"event_type"=>"event_reply_wenda","is_show"=>1,"type"=>"wenda"));
                }

            }else{
                if($answer['user_id'] != $this->bbs_userinfo['user_id']){
                    $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$answer['user_id'],"operator_id"=>$insert_id,"event_type"=>"event_reply_wenda","is_show"=>1,"type"=>"wenda"));
                }
            }

            $totalCount = $answer['commentnum'] + 1;

            $mess['reqStatus'] = true;
            $mess['pageIndex'] = ceil($totalCount/12) - 1;
            $mess['answerId'] = encrypt_answer_id($answerId);
            $mess['totalCount'] = $totalCount;
            $mess['errorMsg'] = "评论成功";
            echo JSON($mess);exit;
        }else{
            $mess['reqStatus'] = false;
            $mess['errorMsg'] = "操作失败，请稍后重试";
            echo JSON($mess);exit;
        }
    }
}
    //增加曝光台问答评论
    function ajax_add_exposure_reply(){
        $this->is_login();
        if($_POST){
            $answerId = isset($_POST['answerId']) ? trim($_POST['answerId']) : 0;//回答id
            $replyTxt = isset($_POST['replyTxt']) ? trim($_POST['replyTxt']) : "";//评论内容
            $replyId = isset($_POST['replyId']) ? trim($_POST['replyId']) : 0;//评论id
            $answerId = decrypt_answer_id($answerId);
            $replyId = $replyId ? decrypt_answer_reply_id($replyId) : 0;

            $answer = $this->db->select("*")->from("bbs_exposure_answer")->where(array("id"=>$answerId,"is_show"=>1))->order_by("id asc")->get()->row_array();
            if(!$answer){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }

            if($replyId){
                $reply = $this->db->select("*")->from("bbs_exposure_reply")->where(array("id"=>$replyId,"answer_id"=>$answerId,"is_show"=>1))->order_by("id asc")->get()->row_array();
                if(!$reply){
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);exit;
                }
            }
            $allergicWord = file_get_contents("http://static.tan66.com/upfiles/files/badwords.txt");
            $allergicWord = str_replace(array("\r\n", "\r", "\n"),'',$allergicWord);
            $allergicWord= explode('|',$allergicWord);
            $info=0;
            for ($i=0;$i<count($allergicWord);$i++){
                $check = substr_count($replyTxt, $allergicWord[$i]);
                if($check>0){
                    $info = $check;
                    break;
                }
            }
            if($info>0){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "检查您的评论内容里面有非法或敏感内容，请修正";
                echo JSON($mess);exit;
            }

            $data = array();
            $data['user_id'] = $this->bbs_userinfo['user_id'];
            $data['answer_id'] = $answerId;
            $data['answer_uid'] = $answer['user_id'];
            $data['wenda_id'] = $answer['wenda_id'];
            $data['wenda_uid'] = $answer['wenda_uid'];
            $data['content'] = $replyTxt;
            $data['create_time'] = time();
            $data['reply_id'] = $reply ? $reply['id'] : 0;
            $data['reply_uid'] = $reply ? $reply['user_id'] : 0;
            $data['is_show'] = 1;

            $this->db->trans_begin();
            $this->db->insert("bbs_exposure_reply",$data);
            $insert_id = $this->db->insert_id();
            $query1 = $this->db->query("update tan_bbs_exposure_answer set commentnum = commentnum + 1 where id = ".$answerId);
            if($insert_id && $query1){
                $this->db->trans_commit();

                //发送消息
                if($reply){
                    if($reply['user_id'] != $this->bbs_userinfo['user_id']){
                        $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$reply['user_id'],"operator_id"=>$insert_id,"event_type"=>"event_reply_wenda","is_show"=>1,"type"=>"wenda"));
                    }

                }else{
                    if($answer['user_id'] != $this->bbs_userinfo['user_id']){
                        $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$answer['user_id'],"operator_id"=>$insert_id,"event_type"=>"event_reply_wenda","is_show"=>1,"type"=>"wenda"));
                    }
                }

                $totalCount = $answer['commentnum'] + 1;

                $mess['reqStatus'] = true;
                $mess['pageIndex'] = ceil($totalCount/12) - 1;
                $mess['answerId'] = encrypt_answer_id($answerId);
                $mess['totalCount'] = $totalCount;
                $mess['errorMsg'] = "评论成功";
                echo JSON($mess);exit;
            }else{
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);exit;
            }
        }
    }
    //问答点赞处理
    function ajax_wd_up(){
        $this->is_login();
        if($_POST){
            $answerId = isset($_POST['answerId']) ? trim($_POST['answerId']) : 0;
            $auid = isset($_POST['answerUid']) ? trim($_POST['answerUid']) : 0;
            $value = isset($_POST['value']) ? trim($_POST['value']) : 0;
            $answerId = decrypt_answer_id($answerId);
            $auid = decrypt_user_id($auid);
            
            $answer = $this->db->select("*")->from("bbs_wenda_answer")->where(array("id"=>$answerId,"is_show"=>1))->order_by("id asc")->get()->row_array();
            if(!$answer){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            if($answer['user_id'] != $auid){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            
            if($answer['user_id'] == $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "不能给自己点赞哦";
                echo JSON($mess);exit;
            }
            
            if($value){//点赞
                $status = $this->db->select("*")->from("bbs_wenda_answer_like")->where(array("user_id"=>$this->bbs_userinfo['user_id'],"answer_id"=>$answerId,"is_del"=>0))->order_by("id desc")->get()->row_array();
                if($status){
                    $this->db->trans_begin();
                    $query1 = $this->db->query("update tan_bbs_wenda_answer_like set is_del = 1 where id = ".$status['id']);
                    $query2 = $this->db->query("update tan_bbs_wenda set likes = likes + 1 where id = ".$answer['wenda_id']);
                    $query3 = $this->db->query("update tan_bbs_wenda_answer set likes = likes + 1 where id = ".$answer['id']);

                    if($query1 && $query2 && $query3){
                        $this->db->trans_commit();
                        $mess['reqStatus'] = true;
                        $mess['count'] = $answer['likes'] + 1;
                        
                        echo JSON($mess);exit;
                    }else{
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);exit;
                    }
                }else{
                    $data = array();
                    $data['user_id'] = $this->bbs_userinfo['user_id'];
                    $data['answer_id'] = $answerId;
                    $data['is_del'] = 1;
                    $data['create_time'] = time();
                    
                    $this->db->trans_begin();
                    $this->db->insert("bbs_wenda_answer_like",$data);
                    $query1 = $this->db->affected_rows();
                    $query2 = $this->db->query("update tan_bbs_wenda set likes = likes + 1 where id = ".$answer['wenda_id']);
                    $query3 = $this->db->query("update tan_bbs_wenda_answer set likes = likes + 1 where id = ".$answerId);
                    if($query1 && $query2 && $query3){
                        $this->db->trans_commit();
                        //发送消息通知
                        $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$answer['user_id'],"operator_id"=>$answer['id'],"event_type"=>"event_like_answer","type"=>"wenda","is_show"=>1));
//                        //更新个人动态
//                        $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$author_id,"event_type"=>"event_focus_author","is_show"=>1));
                        
                        $mess['reqStatus'] = true;
                        $mess['count'] = $answer['likes'] + 1;
                        echo JSON($mess);exit;
                    }else{
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);exit;
                    }
                }
            }else{//取消
                $status = $this->db->select("*")->from("bbs_wenda_answer_like")->where(array("user_id"=>$this->bbs_userinfo['user_id'],"answer_id"=>$answerId,"is_del"=>1))->order_by("id desc")->get()->row_array();
                if(!$status){
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);exit;
                }
                $this->db->trans_begin();
                $query1 = $this->db->query("update tan_bbs_wenda_answer_like set is_del = 0 where id = ".$status['id']);
                    $query2 = $this->db->query("update tan_bbs_wenda set likes = likes - 1 where id = ".$answer['wenda_id']);
                    $query3 = $this->db->query("update tan_bbs_wenda_answer set likes = likes - 1 where id = ".$answer['id']);
                
                if($query1 && $query2 && $query3){
                    $this->db->trans_commit();
                    $mess['reqStatus'] = true;
                    $mess['count'] = $answer['likes'] - 1;
                    echo JSON($mess);exit;
                }else{
                    $this->db->trans_rollback();
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);exit;
                }
            }
        }
    }
    //问答点赞处理
    function ajax_exposure_up(){
        $this->is_login();
        if($_POST){
            $answerId = isset($_POST['answerId']) ? trim($_POST['answerId']) : 0;
            $auid = isset($_POST['answerUid']) ? trim($_POST['answerUid']) : 0;
            $value = isset($_POST['value']) ? trim($_POST['value']) : 0;
            $answerId = decrypt_answer_id($answerId);
            $auid = decrypt_user_id($auid);

            $answer = $this->db->select("*")->from("bbs_exposure_answer")->where(array("id"=>$answerId,"is_show"=>1))->order_by("id asc")->get()->row_array();
            if(!$answer){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            if($answer['user_id'] != $auid){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }

            if($answer['user_id'] == $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "不能给自己点赞哦";
                echo JSON($mess);exit;
            }

            if($value){//点赞
                $status = $this->db->select("*")->from("bbs_exposure_answer_like")->where(array("user_id"=>$this->bbs_userinfo['user_id'],"answer_id"=>$answerId,"is_del"=>0))->order_by("id desc")->get()->row_array();
                if($status){
                    $this->db->trans_begin();
                    $query1 = $this->db->query("update tan_bbs_exposure_answer_like set is_del = 1 where id = ".$status['id']);
                    $query2 = $this->db->query("update tan_bbs_exposure set likes = likes + 1 where id = ".$answer['wenda_id']);
                    $query3 = $this->db->query("update tan_bbs_exposure_answer set likes = likes + 1 where id = ".$answer['id']);

                    if($query1 && $query2 && $query3){
                        $this->db->trans_commit();
                        $mess['reqStatus'] = true;
                        $mess['count'] = $answer['likes'] + 1;

                        echo JSON($mess);exit;
                    }else{
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);exit;
                    }
                }else{
                    $data = array();
                    $data['user_id'] = $this->bbs_userinfo['user_id'];
                    $data['answer_id'] = $answerId;
                    $data['is_del'] = 1;
                    $data['create_time'] = time();

                    $this->db->trans_begin();
                    $this->db->insert("bbs_exposure_answer_like",$data);
                    $query1 = $this->db->affected_rows();
                    $query2 = $this->db->query("update tan_bbs_exposure set likes = likes + 1 where id = ".$answer['wenda_id']);
                    $query3 = $this->db->query("update tan_bbs_exposure_answer set likes = likes + 1 where id = ".$answerId);
                    if($query1 && $query2 && $query3){
                        $this->db->trans_commit();
                        //发送消息通知
                        $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$answer['user_id'],"operator_id"=>$answer['id'],"event_type"=>"event_like_answer","type"=>"exposure","is_show"=>1));
//                        //更新个人动态
//                        $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$author_id,"event_type"=>"event_focus_author","is_show"=>1));

                        $mess['reqStatus'] = true;
                        $mess['count'] = $answer['likes'] + 1;
                        echo JSON($mess);exit;
                    }else{
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);exit;
                    }
                }
            }else{//取消
                $status = $this->db->select("*")->from("bbs_exposure_answer_like")->where(array("user_id"=>$this->bbs_userinfo['user_id'],"answer_id"=>$answerId,"is_del"=>1))->order_by("id desc")->get()->row_array();
                if(!$status){
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);exit;
                }
                $this->db->trans_begin();
                $query1 = $this->db->query("update tan_bbs_exposure_answer_like set is_del = 0 where id = ".$status['id']);
                $query2 = $this->db->query("update tan_bbs_exposure set likes = likes - 1 where id = ".$answer['wenda_id']);
                $query3 = $this->db->query("update tan_bbs_exposure_answer set likes = likes - 1 where id = ".$answer['id']);

                if($query1 && $query2 && $query3){
                    $this->db->trans_commit();
                    $mess['reqStatus'] = true;
                    $mess['count'] = $answer['likes'] - 1;
                    echo JSON($mess);exit;
                }else{
                    $this->db->trans_rollback();
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);exit;
                }
            }
        }
    }
    //增加问答阅读数
    function ajax_wd_read_up(){
        if($_GET){
            $wenda_id = isset($_GET['wenda_id']) ? trim($_GET['wenda_id']) : 0;
            $uuid = isset($_GET['uuid']) ? trim($_GET['uuid']) : 0;
            $wenda_id = decrypt_wenda_id($wenda_id);
            $uuid = decrypt_user_id($uuid);
            if($uuid == $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                echo JSON($mess);exit;
            }
            $wenda = $this->db->select("id,title,questioner_id,readnum")->from("bbs_wenda")->where(array("id"=>$wenda_id))->get()->row_array();
            if(!$wenda){
                $mess['reqStatus'] = false;
                echo JSON($mess);exit;
            }
            if($wenda['questioner_id'] == $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                echo JSON($mess);exit;
            }
            $this->db->trans_begin();
            $query = $this->db->query("update tan_bbs_wenda set readnum = readnum + 1 where id = ".$wenda_id);
            if($query){
                $this->db->trans_commit();
                
                $mess['reqStatus'] = true;
                $mess['readNum'] = $wenda['readnum'] + 1;
                echo JSON($mess);exit;
            }else{
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                echo JSON($mess);exit;
            }
        }
        
    }
    
    //关注问答
    function ajax_wd_care(){
        $this->is_login();
        if($_POST){
            $wenda_id = isset($_POST['wenda_id']) ? trim($_POST['wenda_id']) : 0;
            $uuid = isset($_POST['uuid']) ? trim($_POST['uuid']) : 0;
            $value = isset($_POST['value']) ? trim($_POST['value']) : 0;
            $wenda_id = decrypt_wenda_id($wenda_id);
            $uuid = decrypt_user_id($uuid);
            
            $wenda = $this->db->select("id,questioner_id,focusnum")->from("bbs_wenda")->where(array("id"=>$wenda_id))->order_by("id asc")->get()->row_array();
            if(!$wenda){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            if($wenda['questioner_id'] != $uuid){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            
            if($wenda['questioner_id'] == $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "不能关注自己的问答哦";
                echo JSON($mess);exit;
            }
            
            if($value){//关注
                $status = $this->db->select("*")->from("bbs_wenda_care")->where(array("user_id"=>$this->bbs_userinfo['user_id'],"wenda_id"=>$wenda_id,"is_del"=>0))->order_by("id desc")->get()->row_array();
                if($status){
                    $this->db->trans_begin();
                    $query1 = $this->db->query("update tan_bbs_wenda_care set is_del = 1 where id = ".$status['id']);
                    $query2 = $this->db->query("update tan_bbs_wenda set focusnum = focusnum + 1 where id = ".$wenda_id);
                    $query3 = $this->db->query("update tan_bbs_count set follow_question_count = follow_question_count + 1 where user_id = ".$this->bbs_userinfo['user_id']);

                    if($query1 && $query2 && $query3){
                        $this->db->trans_commit();
                        $mess['reqStatus'] = true;
                        $mess['count'] = $wenda['focusnum'] + 1;
                        
                        echo JSON($mess);exit;
                    }else{
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);exit;
                    }
                }else{
                    $data = array();
                    $data['user_id'] = $this->bbs_userinfo['user_id'];
                    $data['wenda_id'] = $wenda_id;
                    $data['wenda_uid'] = $wenda['questioner_id'];
                    $data['is_del'] = 1;
                    $data['create_time'] = time();
                    
                    $this->db->trans_begin();
                    $this->db->insert("bbs_wenda_care",$data);
                    $query1 = $this->db->affected_rows();
                    $query2 = $this->db->query("update tan_bbs_wenda set focusnum = focusnum + 1 where id = ".$wenda_id);
                    $query3 = $this->db->query("update tan_bbs_count set follow_question_count = follow_question_count + 1 where user_id = ".$this->bbs_userinfo['user_id']);
                    if($query1 && $query2 && $query3){
                        $this->db->trans_commit();
                        //发送消息通知
                        $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$wenda['questioner_id'],"operator_id"=>$wenda_id,"event_type"=>"event_care_answer","type"=>"wenda","is_show"=>1));
//                        //更新个人动态
//                        $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$author_id,"event_type"=>"event_focus_author","is_show"=>1));
                        
                        $mess['reqStatus'] = true;
                        $mess['count'] = $wenda['focusnum'] + 1;
                        echo JSON($mess);exit;
                    }else{
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);exit;
                    }
                }
            }else{//取消
                $status = $this->db->select("*")->from("bbs_wenda_care")->where(array("user_id"=>$this->bbs_userinfo['user_id'],"wenda_id"=>$wenda_id,"is_del"=>1))->order_by("id desc")->get()->row_array();
                if(!$status){
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);exit;
                }
                $this->db->trans_begin();
                $query1 = $this->db->query("update tan_bbs_wenda_care set is_del = 0 where id = ".$status['id']);
                $query2 = $this->db->query("update tan_bbs_wenda set focusnum = focusnum - 1 where id = ".$wenda_id);
                $query3 = $this->db->query("update tan_bbs_count set follow_question_count = follow_question_count - 1 where user_id = ".$this->bbs_userinfo['user_id']);
                
                if($query1 && $query2 && $query3){
                    $this->db->trans_commit();
                    $mess['reqStatus'] = true;
                    $mess['count'] = $wenda['focusnum'] - 1;
                    echo JSON($mess);exit;
                }else{
                    $this->db->trans_rollback();
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);exit;
                }
            }
        }
    }
    //关注问答
    function ajax_exposure_care(){
        $this->is_login();
        if($_POST){
            $wenda_id = isset($_POST['wenda_id']) ? trim($_POST['wenda_id']) : 0;
            $uuid = isset($_POST['uuid']) ? trim($_POST['uuid']) : 0;
            $value = isset($_POST['value']) ? trim($_POST['value']) : 0;
            $wenda_id = decrypt_wenda_id($wenda_id);
            $uuid = decrypt_user_id($uuid);

            $wenda = $this->db->select("id,questioner_id,focusnum")->from("bbs_exposure")->where(array("id"=>$wenda_id))->order_by("id asc")->get()->row_array();
            if(!$wenda){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            if($wenda['questioner_id'] != $uuid){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }

            if($wenda['questioner_id'] == $this->bbs_userinfo['user_id']){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "不能关注自己的问答哦";
                echo JSON($mess);exit;
            }
            if($value){//关注
                $status = $this->db->select("*")->from("bbs_exposure_care")->where(array("user_id"=>$this->bbs_userinfo['user_id'],"wenda_id"=>$wenda_id,"is_del"=>0))->order_by("id desc")->get()->row_array();
                if($status){
                    $this->db->trans_begin();
                    $query1 = $this->db->query("update tan_bbs_exposure_care set is_del = 1 where id = ".$status['id']);
                    $query2 = $this->db->query("update tan_bbs_exposure set focusnum = focusnum + 1 where id = ".$wenda_id);
                    $query3 = $this->db->query("update tan_bbs_count set follow_question_count = follow_question_count + 1 where user_id = ".$this->bbs_userinfo['user_id']);

                    if($query1 && $query2 && $query3){
                        $this->db->trans_commit();
                        $mess['reqStatus'] = true;
                        $mess['count'] = $wenda['focusnum'] + 1;

                        echo JSON($mess);exit;
                    }else{
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);exit;
                    }
                }else{
                    $data = array();
                    $data['user_id'] = $this->bbs_userinfo['user_id'];
                    $data['wenda_id'] = $wenda_id;
                    $data['wenda_uid'] = $wenda['questioner_id'];
                    $data['is_del'] = 1;
                    $data['create_time'] = time();

                    $this->db->trans_begin();
                    $this->db->insert("bbs_exposure_care",$data);
                    $query1 = $this->db->affected_rows();
                    $query2 = $this->db->query("update tan_bbs_exposure set focusnum = focusnum + 1 where id = ".$wenda_id);
                    $query3 = $this->db->query("update tan_bbs_count set follow_question_count = follow_question_count + 1 where user_id = ".$this->bbs_userinfo['user_id']);
                    if($query1 && $query2 && $query3){
                        $this->db->trans_commit();
                        //发送消息通知
                        $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$wenda['questioner_id'],"operator_id"=>$wenda_id,"event_type"=>"event_care_answer","type"=>"exposure","is_show"=>1));
//                        //更新个人动态
//                        $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$author_id,"event_type"=>"event_focus_author","is_show"=>1));

                        $mess['reqStatus'] = true;
                        $mess['count'] = $wenda['focusnum'] + 1;
                        echo JSON($mess);exit;
                    }else{
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);exit;
                    }
                }
            }else{//取消
                $status = $this->db->select("*")->from("bbs_exposure_care")->where(array("user_id"=>$this->bbs_userinfo['user_id'],"wenda_id"=>$wenda_id,"is_del"=>1))->order_by("id desc")->get()->row_array();
                if(!$status){
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);exit;
                }
                $this->db->trans_begin();
                $query1 = $this->db->query("update tan_bbs_exposure_care set is_del = 0 where id = ".$status['id']);
                $query2 = $this->db->query("update tan_bbs_exposure set focusnum = focusnum - 1 where id = ".$wenda_id);
                $query3 = $this->db->query("update tan_bbs_count set follow_question_count = follow_question_count - 1 where user_id = ".$this->bbs_userinfo['user_id']);

                if($query1 && $query2 && $query3){
                    $this->db->trans_commit();
                    $mess['reqStatus'] = true;
                    $mess['count'] = $wenda['focusnum'] - 1;
                    echo JSON($mess);exit;
                }else{
                    $this->db->trans_rollback();
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);exit;
                }
            }
        }
    }
    //问答设置最佳答案
    function ajax_wd_best(){
        $this->is_login();
        if($_POST){
            $wenda_id = isset($_POST['wendaId']) ? trim($_POST['wendaId']) : 0;
            $answer_id = isset($_POST['answerId']) ? trim($_POST['answerId']) : 0;
            $uuid = isset($_POST['uuid']) ? trim($_POST['uuid']) : 0;
            $wenda_id = decrypt_wenda_id($wenda_id);
            $answer_id = decrypt_answer_id($answer_id);
            $uuid = decrypt_user_id($uuid);
            
            if($this->bbs_userinfo['user_id'] != $uuid){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            
            $wenda = $this->db->select("id,questioner_id,answer_id")->from("bbs_wenda")->where(array('id'=>$wenda_id))->order_by("id desc")->get()->row_array();
            if($wenda['answer_id']){//问题已经有答案了
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            
            if($wenda['questioner_id'] != $uuid){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);exit;
            }
            
            $answer = $this->db->select("id,user_id")->from("bbs_wenda_answer")->where(array('id'=>$answer_id))->order_by("id desc")->get()->row_array();
            if(!$answer){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "此回答不存在或已被删除";
                echo JSON($mess);exit;
            }
            $this->db->trans_begin();
            $query1 = $this->db->query("update tan_bbs_wenda set answer_id = $answer[id],answer_uid = $answer[user_id] where id = $wenda_id");
            $query2 = $this->db->query("update tan_bbs_wenda_answer set is_answer = 1 where id = $answer_id");
            $query3 = $this->db->query("update tan_bbs_count set answer_best_count = answer_best_count + 1 where user_id = $answer[user_id]");
            
            if($query1 && $query2 && $query3){
                $this->db->trans_commit();
                
                
                //发送通知
                $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$answer['user_id'],"operator_id"=>$answer_id,"event_type"=>"event_best_answer","type"=>"wenda","is_show"=>1));
                $mess['reqStatus'] = true;
                $mess['errorMsg'] = "已采纳为最佳答案！";
                echo JSON($mess);exit;
            }else{
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);exit;
            }
            
            
            
            
        }
    }
    //个人空间问题列表
    function ajax_room_question(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $type = isset($_REQUEST['type']) ? trim($_REQUEST['type']) : 0;
            $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
            $uuid = decrypt_user_id($uuid);
            $records_per_page = 10;
            
            if($type == 1){//未解决
                $where = " and answer_id = 0";
            }elseif($type == 2){//已解决
                $where = " and answer_id > 0";
            }else{//全部
                $where = "and 1 = 1";
            }
            $totalCount = $this->db->query("select * from tan_bbs_wenda where questioner_id = $uuid $where order by id desc")->num_rows();
            $list = $this->db->query("select id,title,answernum,tags_name,create_time,answer_id from tan_bbs_wenda where questioner_id = $uuid $where order by id desc limit ".($pageIndex * $records_per_page).",".$records_per_page)->result_array();
            $html = "";
            foreach ($list as $key=>$val){
                if($val['answer_id']){//最佳回答
                    $answer = $this->db->select("id,content")->from("bbs_wenda_answer")->where(array("id"=>$val['answer_id'],"is_show"=>1))->order_by("id desc")->limit(1)->get()->row_array();
                }else{//最新回答
                    $answer = $this->db->select("id,content")->from("bbs_wenda_answer")->where(array("wenda_id"=>$val['id'],"is_show"=>1))->order_by("id desc")->limit(1)->get()->row_array();
                }
                $tags_str = "";
                if($val['tags_name']){
                    $tags_arr = explode(",", $val['tags_name']);
                    foreach ($tags_arr as $v){
                        $v = explode("_", $v);
                        $tags_str .="<a href='".  web_url("wenda/tag-".$v[1])."' target='_blank'>$v[0]</a>";
                    }
                }
                $val['create_time'] = $this->set_time_two($val['create_time']);
                $html .= "<div class='con mt20 pb10'>
                            <div class='right-info fl'>
                                <a href='".web_url("wenda/".encrypt_wenda_id($val['id']))."' target='_blank' class='info-title'>$val[title]</a>
                                <div class='info mt10'>
                                    <i>$val[answernum]回答&nbsp;&nbsp;&nbsp;&nbsp;$val[create_time]</i>
                                </div>
                                <div class='label mt5'>
                                	<div class='label-list'>
                                		$tags_str
                                	</div>
                                </div>
                            </div>
                            <div class='adopt icon-index ".($val['answer_id'] ? "icon-adopt-2" : "icon-adopt-1")." fr'></div><div class='clear'></div>";
                if($answer){
                    $html .= "<a href='".web_url("wenda/".encrypt_wenda_id($val['id'])."/answer-".encrypt_answer_id($answer['id']))."' target='_blank' class='mwenda-reply mt10'>".($val['answer_id'] ? "<span class='error'>最佳回答：</span>" : "最新回答：").  mb_strcut((strip_tags(trim($answer[content]))), 0, 150, "utf-8")."</a>";
                }                
                $html .= "</div>";
            }
            
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $html,
                    "goto" => true
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }
    
    //个人空间回答列表
    function ajax_room_answer(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $type = isset($_REQUEST['type']) ? trim($_REQUEST['type']) : 0;
            $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
            $uuid = decrypt_user_id($uuid);
            $records_per_page = 10;
            $is_self = $this->bbs_userinfo['user_id'] == $uuid;
            if(!$is_self){
                $other_where = " and a.is_show = 1";
            }
            if($type == 1){//未解决
                $where = " and a.is_answer = 0";
            }elseif($type == 2){//已解决
                $where = " and a.is_answer = 1";
            }else{//全部
                $where = "and 1 = 1";
            }
            
            $totalCount = $this->db->query("select a.* from tan_bbs_wenda_answer a where a.user_id = $uuid $where $other_where order by a.id desc")->num_rows();
            $list = $this->db->query("select a.id,a.content,a.wenda_id,a.wenda_uid,a.create_time,a.is_answer,u.head_img,u.nickname,w.title,w.answernum,w.tags_name from tan_bbs_wenda_answer a left join tan_users_info u on u.user_id = a.wenda_uid left join tan_bbs_wenda w on a.wenda_id = w.id where a.user_id = $uuid $where $other_where order by a.id desc limit ".($pageIndex * $records_per_page).",".$records_per_page)->result_array();
            $html = "";
            foreach ($list as $key => $val){
                $time_str = $this->set_time_two($val['create_time']);
                $tags_str = "";
                if($val['tags_name']){
                    $tags_arr = explode(",", $val['tags_name']);
                    foreach ($tags_arr as $v){
                        $v = explode("_", $v);
                        $tags_str .="<a href='".  web_url("wenda/tag-".$v[1])."' target='_blank'>$v[0]</a>";
                    }
                }
                $html .= "<div class='con mt20 pb10'>
                            <div class='left-head fl mr20'>
                                    <a href='".web_url("u/".encrypt_wenda_id($val['wenda_uid']))."' target='_blank' class='header'><img src='$val[head_img]'/></a>
                            </div>
                            <div class='right-info fl'>
                                    <a href='".web_url("wenda/".encrypt_wenda_id($val['wenda_id']))."' target='_blank' class='info-title'>$val[title]</a>
                                    <div class='info mt10'>
                                            提问者：<a href='".web_url("u/".encrypt_user_id($val['wenda_uid']))."' target='_blank' class='name mr20'>$val[nickname]</a>
                                            <i>$val[answernum]回答&nbsp;&nbsp;&nbsp;&nbsp;$time_str</i>
                                    </div>
                                    <div class='label mt5'>
                                    	<div class='label-list'>
                                    		$tags_str
                                    	</div>
                                    </div>
                            </div>
                            <div class='adopt icon-index ".($val['is_answer'] ? "icon-adopt-y" : "icon-adopt-n")." fr'></div>
                            <div class='clear'></div>
                            <a href='".web_url("wenda/".encrypt_wenda_id($val['wenda_id'])."/answer-".encrypt_answer_id($val['id']))."' target='_blank' class='mwenda-reply mt10'>".($is_self ? "我" : "Ta")."的回答：".  mb_strcut((strip_tags(trim($val[content]))), 0, 150, "utf-8")."</a>
                        </div>";
            }
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $html,
                    "goto" => true
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }
    //个人空间关注问题列表
    function ajax_room_follew_question(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $type = isset($_REQUEST['type']) ? trim($_REQUEST['type']) : 0;
            $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
            $uuid = decrypt_user_id($uuid);
            $records_per_page = 10;
            
            if($type == 1){//未解决
                $where = " and w.answer_id = 0 and c.is_del = 1";
            }elseif($type == 2){//已解决
                $where = " and w.answer_id > 0 and c.is_del = 1";
            }else{//全部
                $where = "and c.is_del = 1 and  1 = 1 ";
            }
            $totalCount = $this->db->query("select c.* from tan_bbs_wenda_care c left join tan_bbs_wenda w on c.wenda_id = w.id where c.user_id = $uuid $where order by c.id desc")->num_rows();
            $list = $this->db->query("select c.wenda_id,c.wenda_uid,w.title,w.tags_name,w.create_time,w.answer_id,w.answernum,u.head_img,u.nickname from tan_bbs_wenda_care c left join tan_users_info u on u.user_id = c.wenda_uid left join tan_bbs_wenda w on c.wenda_id = w.id  where c.user_id = $uuid $where order by c.id desc limit ".($pageIndex * $records_per_page).",".$records_per_page)->result_array();
            $html = "";
            foreach ($list as $key=>$val){
                if($val['answer_id']){//最佳回答
                    $answer = $this->db->select("id,content")->from("bbs_wenda_answer")->where(array("id"=>$val['answer_id'],"is_show"=>1))->order_by("id desc")->limit(1)->get()->row_array();
                }else{//最新回答
                    $answer = $this->db->select("id,content")->from("bbs_wenda_answer")->where(array("wenda_id"=>$val['wenda_id'],"is_show"=>1))->order_by("id desc")->limit(1)->get()->row_array();
                }
                $tags_str = "";
                if($val['tags_name']){
                    $tags_arr = explode(",", $val['tags_name']);
                    foreach ($tags_arr as $v){
                        $v = explode("_", $v);
                        $tags_str .="<a href='".  web_url("wenda/tag-".$v[1])."' target='_blank'>$v[0]</a>";
                    }
                }
                $time_str = $this->set_time_two($val['create_time']);
                $html .= "<div class='con mt20 pb10'>
                            <div class='left-head fl mr20'>
                                <a href='".web_url("u/".encrypt_user_id($val['wenda_uid']))."' target='_blank' class='header'><img src='$val[head_img]'/></a>
                            </div>
                            <div class='right-info fl'>
                                    <a href='".web_url("wenda/".encrypt_wenda_id($val['wenda_id']))."' target='_blank' class='info-title'>$val[title]</a>
                                    <div class='info mt10'>
                                            提问者：<a href='".web_url("u/".encrypt_user_id($val['wenda_uid']))."' class='name mr20'>$val[nickname]</a>
                                            <i>$val[answernum]回答&nbsp;&nbsp;&nbsp;&nbsp;$time_str</i>
                                    </div>
                                    <div class='label mt5'>
                                    	<div class='label-list'>
                                    		$tags_str
                                    	</div>
                                    </div>
                            </div>
                            <div class='adopt icon-index ".($val['answer_id'] ? "icon-adopt-2" : "icon-adopt-1")." fr'></div>
                            <div class='clear'></div>";
                if($answer){
                    $html .= "<a href='".web_url("wenda/".encrypt_wenda_id($val['wenda_id'])."/answer-".encrypt_answer_id($answer['id']))."' target='_blank' class='mwenda-reply mt10'>".($val['answer_id'] ? "<span class='error'>最佳回答：</span>" : "最新回答：").  mb_strcut((strip_tags(trim($answer[content]))), 0, 150, "utf-8")."</a>";
                }                     
                $html .= "</div>";
            }
            
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $html,
                    "goto" => true
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }
    
    //问答排行榜
    function ajax_wenda_board(){
        
        $type = isset($_REQUEST['type']) ? trim($_REQUEST['type']) : 1;
        if($type == 1){//金牌回答
            $list = $this->db->query("select c.user_id,c.answer_best_count num,u.head_img,u.nickname from tan_bbs_count c left join tan_users_info u on u.user_id = c.user_id where 1=1 order by answer_best_count desc limit 10")->result_array();
        }elseif($type == 2){//回答
            $list = $this->db->query("select c.user_id,c.answer_count num,u.head_img,u.nickname from tan_bbs_count c left join tan_users_info u on u.user_id = c.user_id where 1=1 order by answer_count desc limit 10")->result_array();
        }else{//点赞
            $list = $this->db->query("select SUM(a.likes) num,a.user_id user_id,u.head_img,u.nickname from tan_bbs_wenda_answer a left join tan_users_info u on u.user_id = a.user_id where 1=1 group by a.user_id order by num desc limit 10")->result_array();
        }
        
        $html = "";
        foreach ($list as $key => $val){
            $medal_type = "";
            if(($key + 1) == 1){
                $medal_type = "icon-billboard-medal1";
                $num_color = "";
            }elseif(($key + 1) == 2){
                $medal_type = "icon-billboard-medal2";
                $num_color = "";
            }elseif(($key + 1) == 3){
                $medal_type = "icon-billboard-medal3";
                $num_color = "";
            }else{
                $num_color = "col666";
            }
            $html .= "<li>
                        <span class='fl ".($medal_type ? $medal_type : "medal")."'>".($medal_type ? "" : ($key + 1))."</span>
                        <a href='".  web_url("u/".  encrypt_user_id($val['user_id']))."' class='head mr20 fl'>
                                <img src='".$val['head_img']."'/>
                        </a>
                       	<div class='fl'>
                        	<a href='".  web_url("u/".  encrypt_user_id($val['user_id']))."' class='name'>$val[nickname]</a>
                        	<p><a href='javascript:void(0);' class='level'>LV 1</a></p>
                        </div>
                        <i class='num fr $num_color'>$val[num]</i>
                    </li>";
        }
        
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "htmlData" => $html
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    
    //打赏排行榜
    function ajax_award_board(){
        
        $type = isset($_REQUEST['type']) ? trim($_REQUEST['type']) : 1;
        if($type == 1){//打赏支出
            $list = $this->db->query("select a.user_id,a.reward_expend num,u.head_img,u.nickname from tan_bbs_account a left join tan_users_info u on u.user_id = a.user_id where 1=1 order by num desc limit 5")->result_array();
        }elseif($type == 2){//打赏收入
            $list = $this->db->query("select a.user_id,a.reward num,u.head_img,u.nickname from tan_bbs_account a left join tan_users_info u on u.user_id = a.user_id where 1=1 order by num desc limit 5")->result_array();
        }
        
        $html = "";
        foreach ($list as $key => $val){
            $medal_type = "";
            if(($key + 1) == 1){
                $medal_type = "icon-billboard-medal1";
                $num_color = "";
            }elseif(($key + 1) == 2){
                $medal_type = "icon-billboard-medal2";
                $num_color = "";
            }elseif(($key + 1) == 3){
                $medal_type = "icon-billboard-medal3";
                $num_color = "";
            }else{
                $num_color = "col666";
            }
            $html .= "<li>
                        <span class='fl ".($medal_type ? $medal_type : "medal")."'>".($medal_type ? "" : ($key + 1))."</span>
                        <a href='".web_url("u/".encrypt_user_id($val['user_id']))."' class='head mr20 fl'>
                            <img src='$val[head_img]'/>
                        </a>
                        <div class='fl'>
                        	<a href='".web_url("u/".encrypt_user_id($val['user_id']))."' class='name fl'>$val[nickname]</a>
                        	<p><a href='javascript:void(0);' class='level'>LV 1</a></p>
                        </div>
                        <i class='num fr $num_color'>$val[num]</i>
                    </li>";
        }
        
        $result = array(
            "reqStatus" => true,
            "data" => array(
                "htmlData" => $html
            )
        );
        echo json_encode($result,JSON_HEX_TAG);die;
    }


    //个人空间问题列表
    function ajax_room_exposure(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
            $uuid = decrypt_user_id($uuid);
            $records_per_page = 10;

            $where = "and 1 = 1";

            $totalCount = $this->db->query("select * from tan_bbs_exposure where type=1 AND questioner_id = $uuid $where order by id desc")->num_rows();
            $list = $this->db->query("select id,title,answernum,tags_name,create_time,answer_id from tan_bbs_exposure where type=1 AND questioner_id = $uuid $where order by id desc limit ".($pageIndex * $records_per_page).",".$records_per_page)->result_array();
            $html = "";
            foreach ($list as $key=>$val){

                $tags_str = "";
                if($val['tags_name']){
                    $tags_arr = explode(",", $val['tags_name']);
                    foreach ($tags_arr as $v){
                        $v = explode("_", $v);
                        $tags_str .="<a href='".  web_url("exposure/tag-".$v[1])."' target='_blank'>$v[0]</a>";
                    }
                }
                $val['create_time'] = $this->set_time_two($val['create_time']);
                $html .= "<div class='con mt20 pb10'>
                            <div class='right-info fl'>
                                <a href='".web_url("exposure/".encrypt_wenda_id($val['id']))."' target='_blank' class='info-title'>$val[title]</a>
                                <div class='info mt10'>
                                    <i>$val[answernum]回复&nbsp;&nbsp;&nbsp;&nbsp;$val[create_time]</i>
                                </div>
                                <div class='label mt5'>
                                	<div class='label-list'>
                                		$tags_str
                                	</div>
                                </div>
                            </div>
                            <div class='clear'></div>";

                $html .= "</div>";
            }

            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $html,
                    "goto" => true
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }

    //个人空间回答列表
    function ajax_room_exposure_re(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
            $uuid = decrypt_user_id($uuid);
            $records_per_page = 10;
            $is_self = $this->bbs_userinfo['user_id'] == $uuid;
            if(!$is_self){
                $other_where = " and a.is_show = 1";
            }

            $where = "and 1 = 1";

            $totalCount = $this->db->query("select a.* from tan_bbs_exposure_answer a left join tan_bbs_exposure w on a.wenda_id = w.id where w.type=1 AND a.user_id = $uuid $where $other_where order by a.id desc")->num_rows();
            $list = $this->db->query("select a.id,a.content,a.wenda_id,a.wenda_uid,a.create_time,a.is_answer,u.head_img,u.nickname,w.title,w.answernum,w.tags_name from tan_bbs_exposure_answer a left join tan_users_info u on u.user_id = a.wenda_uid left join tan_bbs_exposure w on a.wenda_id = w.id where w.type=1 AND a.user_id = $uuid $where $other_where order by a.id desc limit ".($pageIndex * $records_per_page).",".$records_per_page)->result_array();
            $html = "";
            foreach ($list as $key => $val){
                $time_str = $this->set_time_two($val['create_time']);
                $tags_str = "";
                if($val['tags_name']){
                    $tags_arr = explode(",", $val['tags_name']);
                    foreach ($tags_arr as $v){
                        $v = explode("_", $v);
                        $tags_str .="<a href='".  web_url("exposure/tag-".$v[1])."' target='_blank'>$v[0]</a>";
                    }
                }
                $html .= "<div class='con mt20 pb10'>
                            <div class='left-head fl mr20'>
                                    <a href='".web_url("u/".encrypt_wenda_id($val['wenda_uid']))."' target='_blank' class='header'><img src='$val[head_img]'/></a>
                            </div>
                            <div class='right-info fl'>
                                    <a href='".web_url("exposure/".encrypt_wenda_id($val['wenda_id']))."' target='_blank' class='info-title'>$val[title]</a>
                                    <div class='info mt10'>
                                            曝光者：<a href='".web_url("u/".encrypt_user_id($val['wenda_uid']))."' target='_blank' class='name mr20'>$val[nickname]</a>
                                            <i>$val[answernum]回复&nbsp;&nbsp;&nbsp;&nbsp;$time_str</i>
                                    </div>
                                    <div class='label mt5'>
                                    	<div class='label-list'>
                                    		$tags_str
                                    	</div>
                                    </div>
                            </div>
                            <div class='clear'></div>
                            <a href='".web_url("exposure/".encrypt_wenda_id($val['wenda_id'])."/answer-".encrypt_answer_id($val['id']))."' target='_blank' class='mwenda-reply mt10'>".($is_self ? "我" : "Ta")."的回复：".  mb_strcut((strip_tags(trim($val[content]))), 0, 150, "utf-8")."</a>
                        </div>";
            }
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $html,
                    "goto" => true
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }
    //个人空间关注问题列表
    function ajax_room_follew_exposure(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
            $uuid = decrypt_user_id($uuid);
            $records_per_page = 10;

            $where = "and c.is_del = 1 and  1 = 1 ";

            $totalCount = $this->db->query("select c.* from tan_bbs_exposure_care c left join tan_bbs_exposure w on c.wenda_id = w.id where w.type=1 and c.user_id = $uuid $where order by c.id desc")->num_rows();
            $list = $this->db->query("select c.wenda_id,c.wenda_uid,w.title,w.tags_name,w.create_time,w.answer_id,w.answernum,u.head_img,u.nickname from tan_bbs_exposure_care c left join tan_users_info u on u.user_id = c.wenda_uid left join tan_bbs_exposure w on c.wenda_id = w.id  where w.type=1 and c.user_id = $uuid $where order by c.id desc limit ".($pageIndex * $records_per_page).",".$records_per_page)->result_array();
            $html = "";
            foreach ($list as $key=>$val){

                $tags_str = "";
                if($val['tags_name']){
                    $tags_arr = explode(",", $val['tags_name']);
                    foreach ($tags_arr as $v){
                        $v = explode("_", $v);
                        $tags_str .="<a href='".  web_url("exposure/tag-".$v[1])."' target='_blank'>$v[0]</a>";
                    }
                }
                $time_str = $this->set_time_two($val['create_time']);
                $html .= "<div class='con mt20 pb10'>
                            <div class='left-head fl mr20'>
                                <a href='".web_url("u/".encrypt_user_id($val['wenda_uid']))."' target='_blank' class='header'><img src='$val[head_img]'/></a>
                            </div>
                            <div class='right-info fl'>
                                    <a href='".web_url("exposure/".encrypt_wenda_id($val['wenda_id']))."' target='_blank' class='info-title'>$val[title]</a>
                                    <div class='info mt10'>
                                            曝光者：<a href='".web_url("u/".encrypt_user_id($val['wenda_uid']))."' class='name mr20'>$val[nickname]</a>
                                            <i>$val[answernum]回复&nbsp;&nbsp;&nbsp;&nbsp;$time_str</i>
                                    </div>
                                    <div class='label mt5'>
                                    	<div class='label-list'>
                                    		$tags_str
                                    	</div>
                                    </div>
                            </div>
                            <div class='clear'></div>";

                $html .= "</div>";
            }

            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $html,
                    "goto" => true
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }

    //个人空间回答列表
    function ajax_room_information_re(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
            $uuid = decrypt_user_id($uuid);
            $records_per_page = 10;
            $is_self = $this->bbs_userinfo['user_id'] == $uuid;
            if(!$is_self){
                $other_where = " and a.is_show = 1";
            }

            $where = "and 1 = 1";

            $totalCount = $this->db->query("select a.* from tan_bbs_exposure_answer a left join tan_bbs_exposure w on a.wenda_id = w.id where w.type=2 AND a.user_id = $uuid $where $other_where order by a.id desc")->num_rows();
            $list = $this->db->query("select a.id,a.content,a.wenda_id,a.wenda_uid,a.create_time,a.is_answer,u.head_img,u.nickname,w.title,w.answernum,w.tags_name from tan_bbs_exposure_answer a left join tan_users_info u on u.user_id = a.wenda_uid left join tan_bbs_exposure w on a.wenda_id = w.id where w.type=2 AND a.user_id = $uuid $where $other_where order by a.id desc limit ".($pageIndex * $records_per_page).",".$records_per_page)->result_array();
            $html = "";
            foreach ($list as $key => $val){
                $time_str = $this->set_time_two($val['create_time']);
                $tags_str = "";
                if($val['tags_name']){
                    $tags_arr = explode(",", $val['tags_name']);
                    foreach ($tags_arr as $v){
                        $v = explode("_", $v);
                        $tags_str .="<a href='".  web_url("exposure/tag-".$v[1])."' target='_blank'>$v[0]</a>";
                    }
                }
                $html .= "<div class='con mt20 pb10'>
                            <div class='left-head fl mr20'>
                                    <a href='".web_url("u/".encrypt_wenda_id($val['wenda_uid']))."' target='_blank' class='header'><img src='$val[head_img]'/></a>
                            </div>
                            <div class='right-info fl'>
                                    <a href='".web_url("exposure/".encrypt_wenda_id($val['wenda_id']))."' target='_blank' class='info-title'>$val[title]</a>
                                    <div class='info mt10'>
                                            曝光者：<a href='".web_url("u/".encrypt_user_id($val['wenda_uid']))."' target='_blank' class='name mr20'>$val[nickname]</a>
                                            <i>$val[answernum]回复&nbsp;&nbsp;&nbsp;&nbsp;$time_str</i>
                                    </div>
                                    <div class='label mt5'>
                                    	<div class='label-list'>
                                    		$tags_str
                                    	</div>
                                    </div>
                            </div>
                            <div class='clear'></div>
                            <a href='".web_url("exposure/".encrypt_wenda_id($val['wenda_id'])."/answer-".encrypt_answer_id($val['id']))."' target='_blank' class='mwenda-reply mt10'>".($is_self ? "我" : "Ta")."的回复：".  mb_strcut((strip_tags(trim($val[content]))), 0, 150, "utf-8")."</a>
                        </div>";
            }
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $html,
                    "goto" => true
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }


    //个人空间任务发布列表
    function ajax_room_taskrel(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $type = isset($_REQUEST['type']) ? trim($_REQUEST['type']) : 0;
            $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
            $uuid = decrypt_user_id($uuid);
            $records_per_page = 10;
            $account = $this->account_model->get($this->userinfo['user_id']);
            $liub_balance = floor($account['balance']/10000);
            $where = " and t.is_delete = 0 ";
            if($type == 1){//未完成
                $where .= " and t.is_end = 0";
            }elseif($type == 2){//已完成
                $where .= " and t.is_end = 1";
            }else{//全部
                $where .= "and 1 = 1";
            }

            $totalCount = $this->db->query("select t.* from tan_task t where t.uid = $uuid $where order by t.tid desc")->num_rows();
            $list = $this->db->query("select t.* from tan_task t where t.uid = $uuid $where  order by t.tid desc limit ".($pageIndex * $records_per_page).",".$records_per_page)->result_array();

            foreach ($list as $key => $val){
                $time_str = $this->set_time_two($val['add_time']);
//                $submit_subtask = $this->db->query("select st.* from tan_subtasks st where st.tid = ".$val['tid']." and (select c.status from tan_complaint c where c.sid=st.sid) not in(4,5)  order by st.sid desc")->num_rows();
                $list[$key]['ture_subtask'] = $this->db->query("select st.* from tan_subtasks st where st.tid = ".$val['tid']." and st.is_end < 2 order by st.sid desc")->num_rows();
                $list[$key]['fals_subtask'] = $this->db->query("select st.* from tan_subtasks st where st.tid = ".$val['tid']." and st.is_end = 2 order by st.sid desc")->num_rows();
//                $appealfail_num = $this->db->query("select c.* from tan_complaint c left join tan_subtasks st on st.sid=c.sid where st.tid=".$val['tid']." and c.status in(4,5) order by c.cid desc")->num_rows();
                $list[$key]['commission'] = round($val['commission']/10000,2);
                $list[$key]['task_status'] = "";
                $list[$key]['rec_sta'] = "";
                if ($val['cate_id']==4){
                    $list[$key]['rec_sta'] .= "<dt><a class='receive-btn' href='javascript:;' onclick='append_money(".encrypt_wenda_id($val['tid']).",".$liub_balance.")' title='追加资金'>追加资金</a></dt>";
                }

                if($val['is_end']==1){
                    $list[$key]['task_status'] .= "<span class='red'>已结束</span>";
                    $list[$key]['rec_sta'] .= "<dt><a class='receive-btn' href='".web_url("account/taskreclog")."?tid=".encrypt_wenda_id($val['tid'])."' title='领取记录'>领取记录</a></dt>";
                }elseif($val['is_end']==0){
                    if($val['status']==1){
                        $list[$key]['task_status'] .= "<span class='green'>审核通过</span>&nbsp;";
                        if ($val['is_pause']){
                            $list[$key]['rec_sta'] .= "<dt><a class='paused-btn' href='javascript:;' onclick='pausetask(".encrypt_wenda_id($val['tid']).",0)' title='开启领取'>开启领取</a></dt>";
                        }else{
                            $list[$key]['rec_sta'] .= "<dt><a class='paused-btn' href='javascript:;' onclick='pausetask(".encrypt_wenda_id($val['tid']).",1)' title='暂停领取'>暂停领取</a></dt>";
                        }

                        $list[$key]['rec_sta'] .= "<dt><a class='receive-btn' href='".web_url("account/taskreclog")."?tid=".encrypt_wenda_id($val['tid'])."' title='领取记录'>领取记录</a></dt>";
                    }elseif($val['status']==2){
                        $list[$key]['task_status'] .= "<span class='red'>审核未通过</span>&nbsp;";
                    }elseif($val['status']==3){
                        $list[$key]['task_status'] .= "<span class='red'>已支付</span>&nbsp;";
                        $list[$key]['rec_sta'] .= "<dt><a class='receive-btn' href='".web_url("task/edit")."?tid=".encrypt_wenda_id($val['tid'])."' title='修改任务'>修改</a></dt>";
                    }elseif($val['status']==0){
                        $list[$key]['task_status'] .= "<span class='blue'>未支付</span>&nbsp;";
                        $list[$key]['rec_sta'] .= "<dt><a class='receive-btn' href='".web_url("task/edit")."?tid=".encrypt_wenda_id($val['tid'])."' title='修改任务'>修改</a></dt>";
                        $list[$key]['rec_sta'] .= "<dt><a class='paused-btn' href='".web_url("task/pay")."?tid=".encrypt_wenda_id($val['tid'])."' title='立即支付'>立即支付</a></dt>";
                    }
                    $list[$key]['rec_sta'] .= "<dt><a class='close-btn' href='javascript:void(0);' onclick='closetask(".encrypt_wenda_id($val['tid']).");' title='关闭任务'>关闭任务</a></dt>";
                    $list[$key]['task_status'] .= "&nbsp;<span class='blue'>未结束</span>";
                }

                /* lht 2018/5/18 16:26 已经领取的额度 */
                $list[$key]['received_money'] = $this->task_model->subtask_invest_money_count($val['tid']);
                $list[$key]['received_money'] = empty($list[$key]['received_money'])?0:$list[$key]['received_money'];

                $list[$key]['task_url'] = web_url("task/".encrypt_wenda_id($val['tid']));
                $list[$key]['subtask_url'] = web_url("account/taskreclog")."?tid=".encrypt_wenda_id($val['tid']);

//                $html .= "<div class='con mt20 pb10'>
//
//                            <div class='right-info fl'>
//                                <a href='".web_url("task/".encrypt_wenda_id($val['tid']))."' target='_blank' class='info-title'>$val[title]</a>
//                                <div class='info mt10'>
//                                        佣金：$val[commission]&nbsp;&nbsp;&nbsp;&nbsp;
//                                        押金：$val[deposit]&nbsp;&nbsp;&nbsp;&nbsp;
//                                        赞助费：$val[sponsorship_money]&nbsp;&nbsp;&nbsp;&nbsp;
//                                        子任务：$val[sub_num]&nbsp;&nbsp;&nbsp;&nbsp;
//                                        已领取：<a href='".web_url("account/taskreclog")."?tid=".encrypt_wenda_id($val['tid'])."' title='领取记录'>$submit_subtask</a>&nbsp;&nbsp;&nbsp;&nbsp;
//                                        申诉：$appeal_num&nbsp;&nbsp;&nbsp;&nbsp;
//                                        状态：$task_status
//                                </div>
//                            </div>
//                            <div class='fr'>
//                                $rec_sta
//                            </div>
//                            <div class='clear'></div>
//                        </div>";
            }
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $list,
                    "goto" => true
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }

    //个人空间任务领取记录
    function ajax_room_taskreclog(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $type = isset($_REQUEST['type']) ? trim($_REQUEST['type']) : 0;
            $ttid = isset($_REQUEST['ttid']) ? trim($_REQUEST['ttid']) : 0;
            $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
            $ttid = decrypt_wenda_id($ttid);
            $uuid = decrypt_user_id($uuid);
            $records_per_page = 10;

            if($type == 1){//未验证
                $where = " and st.status = 0 and st.is_post = 1";
            }elseif($type == 2){//已验证
                $where = " and st.status > 0";
            }elseif($type == 3){//申诉
                $where = " and (select count(*) from tan_complaint ct where ct.sid = st.sid)>0 ";
            }else{//全部
                $where = "and 1 = 1";
            }

            $totalCount = $this->db->query("select st.* from tan_subtasks st where st.tid = $ttid $where order by st.sid desc")->num_rows();
            $list = $this->db->query("select st.*,t.title,t.commission,u.username,t.cate_id from tan_subtasks st left join tan_task t on t.tid=st.tid left join tan_users u on u.user_id = st.uid where st.tid = $ttid $where order by st.is_post desc, concat(st.status, st.receive_time) asc limit ".($pageIndex * $records_per_page).",".$records_per_page)->result_array();

            foreach ($list as $key => $val){
                $list[$key]['add_time'] = $val['add_time']?date('Y-m-d H:i:s',$val['add_time']):'';
                $list[$key]['receive_time'] = $val['receive_time']?date('Y-m-d H:i:s',$val['receive_time']):'未提交';
                $list[$key]['validate_text'] = "";
                if ($val['validate']){
                    $validate = unserialize($val['validate']);
                    $list[$key]['validate_text'] .= isset($validate['name'])?'<p class="name">'.$validate['name'].'</p>':'';
                    $list[$key]['validate_text'] .= isset($validate['phone'])?'<p class="name">'.$validate['phone'].'</p>':'';
                }
                $appeal_info = $this->db->query("select c.* from tan_complaint c where c.sid=".$val['sid']." order by c.cid desc")->row_array();
                $list[$key]['task_id'] = encrypt_wenda_id($val['tid']);
                $list[$key]['commission'] = ($val['commission'])/10000;
                $list[$key]['task_status'] = '';
                $list[$key]['rec_sta'] = '';
                if ($val['cate_id']==4){
                    if ($val['qualification']==1){
                        if ($val['apply_end']==1){
                            $list[$key]['task_status'] .= "&nbsp;<span class='green'>已申请结束</span>";
                            if ($val['is_end']==1){
                                $list[$key]['validate_text'] .= "完成数量：".$val['end_num'];
                            }
                        }else {
                            $list[$key]['rec_sta'] .= '<button onclick="apply_finish(' . encrypt_wenda_id($val['tid']) . ',' . encrypt_wenda_id($val['sid']) . ')">申请结束</button>';
                            $list[$key]['task_status'] .= '&nbsp;<span class="green">资质通过</span>';
                        }
                    }elseif ($val['qualification']==2){
                        $list[$key]['task_status'] .= '&nbsp;<span class="red">资质未通过</span>';
                    }else{
                        $list[$key]['task_status'] .= '&nbsp;<span class="red">资质未验证</span>';
                    }
                }else{
                    if($val['is_post'] == 1){
                        if($val['status']==4 ){
                            $list[$key]['task_status'] .= '<span class="error">已取消</span>&nbsp;';
                        }elseif ($val['status']==2){
                            $list[$key]['task_status'] .= '&nbsp;<span class="red">未通过</span>';
                        }elseif ($val['status']==1){
                            $list[$key]['task_status'] .= '&nbsp;<span class="green">已通过</span>';
                        }else{
                            $list[$key]['rec_sta'] .= '<button onclick="check_task('.encrypt_wenda_id($val['sid']).',1)">通过</button><button onclick="check_task('.encrypt_wenda_id($val['sid']).',2)">不通过</button>';
                            $list[$key]['task_status'] .= '&nbsp;<span class="blue">等待验证</span>';
                        }
                    }elseif($val['is_post'] == 0){
                        if($val['status']==4){
                            $list[$key]['task_status'] .= '<span class="error">已取消</span>&nbsp;';
                        }else if ($val['status']==3){
                            $list[$key]['task_status'] .= '&nbsp;<span class="error">超时失败</span>';
                        }else{
                            $list[$key]['task_status'] .= '<span class="error">待提交</span>&nbsp;';
                        }
                    }
                    if($type == 3){
                        $list[$key]['rec_sta'] .= '<button class="btn-detail" onclick="location=\'/account/taskreappeal.html?sid='.encrypt_wenda_id($val['sid']).'\'">申诉详情</button>';
                    }
                }

                $list[$key]['rec_sta'] .= '<button class="btn-detail" onclick="location=\'/account/taskreclogdetail.html?sid='.$val['sid'].'\'">详情</button>';
//                $html .= "<div class='con mt20 pb10'>
//                            <div class='right-info fl'>
//                                <a>$val[task_sn]</a>
//                                <div class='info mt10'>
//                                        领取人：$val[username]&nbsp;&nbsp;&nbsp;&nbsp;
//                                        提交时间：$val[receive_time]&nbsp;&nbsp;&nbsp;&nbsp;
//                                        认证信息：$val[validate]&nbsp;&nbsp;&nbsp;&nbsp;
//                                        状态：$task_status
//                                </div>
//                            </div>
//                            <div class='fr' style=''>
//                                $rec_sta
//                            </div>
//                            <div class='clear'></div>
//                        </div>";
            }
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $list,
                    "goto" => true
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }

    //个人空间任务领取记录all
    function ajax_room_taskrecalllog(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $type = isset($_REQUEST['type']) ? trim($_REQUEST['type']) : 0;

            $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;

            $uuid = decrypt_user_id($uuid);
            $records_per_page = 10;
            $task_sn = isset($_REQUEST['task_sn']) ? trim($_REQUEST['task_sn']) : '';

            if($type == 1){//未验证
                $where = " and st.status = 0 and st.is_post = 1";
            }elseif($type == 2){//已验证
                $where = " and st.status > 0";
            }elseif($type == 3){//申诉
                $where = " and (select count(*) from tan_complaint ct where ct.sid = st.sid)>0 ";
            }else{//全部
                $where = "and 1 = 1";
            }
            if($task_sn){
                $where .= " and st.task_sn='{$task_sn}'";
            }
            $totalCount = $this->db->query("select * from tan_subtasks st where st.tid in (select tid from tan_task where uid={$uuid} {$where})")->num_rows();
            $list = $this->db->query("select st.*,t.title,t.commission,u.username,t.cate_id from tan_subtasks st
                                  left join tan_task t on t.tid=st.tid 
                                  left join tan_users u on u.user_id = st.uid 
                                  where st.tid in (select tid from tan_task where uid={$uuid}) {$where} order by st.is_post desc, concat(st.status, st.receive_time) asc limit ".($pageIndex * $records_per_page).",".$records_per_page)->result_array();

            foreach ($list as $key => $val){
                $list[$key]['add_time'] = $val['add_time']?date('Y-m-d H:i:s',$val['add_time']):'';
                $list[$key]['receive_time'] = $val['receive_time']?date('Y-m-d H:i:s',$val['receive_time']):'未提交';
                $list[$key]['validate_text'] = "";
                if ($val['validate']){
                    $validate = unserialize($val['validate']);
                    $list[$key]['validate_text'] .= isset($validate['name'])?'<p class="name">'.$validate['name'].'</p>':'';
                    $list[$key]['validate_text'] .= isset($validate['phone'])?'<p class="name">'.$validate['phone'].'</p>':'';
                }
                $appeal_info = $this->db->query("select c.* from tan_complaint c where c.sid=".$val['sid']." order by c.cid desc")->row_array();
                $list[$key]['task_id'] = encrypt_wenda_id($val['tid']);
                $list[$key]['commission'] = ($val['commission'])/10000;
                $list[$key]['task_status'] = '';
                $list[$key]['rec_sta'] = '';
                if ($val['cate_id']==4){
                    if ($val['qualification']==1){
                        if ($val['apply_end']==1){
                            $list[$key]['task_status'] .= "&nbsp;<span class='green'>已申请结束</span>";
                            if ($val['is_end']==1){
                                $list[$key]['validate_text'] .= "完成数量：".$val['end_num'];
                            }
                        }else {
                            $list[$key]['rec_sta'] .= '<button onclick="apply_finish(' . encrypt_wenda_id($val['tid']) . ',' . encrypt_wenda_id($val['sid']) . ')">申请结束</button>';
                            $list[$key]['task_status'] .= '&nbsp;<span class="green">资质通过</span>';
                        }
                    }elseif ($val['qualification']==2){
                        $list[$key]['task_status'] .= '&nbsp;<span class="red">资质未通过</span>';
                    }else{
                        $list[$key]['task_status'] .= '&nbsp;<span class="red">资质未验证</span>';
                    }
                }else {
                    if ($val['is_post'] == 1) {
                        if ($val['status'] == 4) {
                            $list[$key]['task_status'] .= '<span class="error">已取消</span>&nbsp;';
                        } elseif ($val['status'] == 2) {
                            $list[$key]['task_status'] .= '&nbsp;<span class="red">未通过</span>';
                        } elseif ($val['status'] == 1) {
                            $list[$key]['task_status'] .= '&nbsp;<span class="green">已通过</span>';
                        } else {
                            $list[$key]['rec_sta'] .= '<button onclick="check_task(' . encrypt_wenda_id($val['sid']) . ',1)">通过</button><button onclick="check_task(' . encrypt_wenda_id($val['sid']) . ',2)">不通过</button>';
                            $list[$key]['task_status'] .= '&nbsp;<span class="blue">等待验证</span>';
                        }
                    } elseif ($val['is_post'] == 0) {
                        if ($val['status'] == 4) {
                            $list[$key]['task_status'] .= '<span class="error">已取消</span>&nbsp;';
                        } else if ($val['status'] == 3) {
                            $list[$key]['task_status'] .= '&nbsp;<span class="error">超时失败</span>';
                        } else {
                            $list[$key]['task_status'] .= '<span class="error">待提交</span>&nbsp;';
                        }
                    }
                    if ($type == 3) {
                        $list[$key]['rec_sta'] .= '<button class="btn-detail" onclick="location=\'/account/taskreappeal.html?sid=' . encrypt_wenda_id($val['sid']) . '\'">申诉详情</button>';
                    }
                }
                $list[$key]['rec_sta'] .= '<button class="btn-detail" onclick="location=\'/account/taskreclogdetail.html?sid='.$val['sid'].'\'">详情</button>';
//                $html .= "<div class='con mt20 pb10'>
//                            <div class='right-info fl'>
//                                <a>$val[task_sn]</a>
//                                <div class='info mt10'>
//                                        领取人：$val[username]&nbsp;&nbsp;&nbsp;&nbsp;
//                                        提交时间：$val[receive_time]&nbsp;&nbsp;&nbsp;&nbsp;
//                                        认证信息：$val[validate]&nbsp;&nbsp;&nbsp;&nbsp;
//                                        状态：$task_status
//                                </div>
//                            </div>
//                            <div class='fr' style=''>
//                                $rec_sta
//                            </div>
//                            <div class='clear'></div>
//                        </div>";
            }
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $list,
                    "goto" => true
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }

    //验证任务
    function ajax_checktask(){
        $tsid = isset($_POST['tsid']) ? trim($_POST['tsid']) : 0;

        if ($tsid){
            $tsid = decrypt_wenda_id($tsid);
            $data['status'] = isset($_POST['status']) ? trim($_POST['status']) : 0;
            $data['is_end'] = $data['status']==1?1:0;
            $data['is_gived'] = $data['status']==1?1:0;
            $data['check_time'] = time();
            $data['suggestion'] = isset($_POST['suggestion']) ? trim($_POST['suggestion']) : '';

            $this->db->trans_begin();//开启事务

            if ($data['status']==1){
                $subtask = $this->db->query("select st.*, t.commission,t.cate_id,t.commission_per from tan_subtasks st left join tan_task t on t.tid=st.tid where st.sid=$tsid")->row_array();

                if ($subtask['is_gived']==0){
                    $account = $this->account_model->get($subtask['uid']);
                    if($subtask['cate_id'] == 3){
                        $amount = $subtask['investment_money']*$subtask['commission_per']/100 * 10000;
                    }else{
                        $amount = $subtask['commission'];
                    }

                    $update_account = array(
                        'balance' => $account['balance'] + $amount,//账户余额
                        'total' => $account['total'] + $amount,//总额金额
                    );
                    $res1 = $this->account_model->update($update_account,$subtask['uid']);

                    //弹溜溜明细
                    $finance_list_data = array();
                    $finance_list_data['user_id'] = $subtask['uid'];
                    $finance_list_data['content'] = '任务佣金'.$amount.'溜溜币';
                    $finance_list_data['finance'] = $amount;
                    $finance_list_data['finance_balance'] = $update_account['balance'];
                    $finance_list_data['reward_type'] = 'spread_award';
                    $finance_list_data['type'] = 1;//收入
                    $finance_list_data['create_time'] = time();
                    $finance_list_data['month'] = date("Ym");
                    $finance_list_data['day'] = date("Ymd");
                    $res2 = $this->finance_list_model->insert($finance_list_data);
                }else{
                    $res1 = $res2 = true;
                }
            }else{
                $res1 = $res2 = true;
            }

            $res = $this->db->where(array('sid'=>$tsid))->update('tan_subtasks',$data);
            if ($res && $res1 && $res2){
                $this->db->trans_commit();//提交事务
                $result = array(
                    "reqStatus" => true,
                    "meg"   => "提交成功",
                );
                //log
                $log_content =  $this->task_model->log_content();
                $log_arr = array(
                    'type_id'=>$tsid,
                    'uid'=>$this->userinfo['user_id'],
                    'type' => 1,
                    'content'=>$log_content['judge_task'],
                    'add_time'=>time(),
                );
                $this->task_model->add_subtasks_log($log_arr);
            }else{
                $this->db->trans_rollback();//事务回滚
                $result = array(
                    "reqStatus" => false,
                    "meg"   => "提交失败",
                );
            }
        }else{
            $result = array(
                "reqStatus" => false,
                "meg"   => "数据错误",
            );
        }
        echo json_encode($result,JSON_HEX_TAG);die;

    }
    //申诉通过
    function ajax_appeal_state(){
        $tsid = isset($_REQUEST['tsid']) ? trim($_REQUEST['tsid']) : 0;
        $tscid = isset($_REQUEST['tscid']) ? trim($_REQUEST['tscid']) : 0;
        $status = isset($_REQUEST['status']) ? trim($_REQUEST['status']) : 0;
        $tsid = decrypt_wenda_id($tsid);
        $tscid = decrypt_wenda_id($tscid);
        if ($tsid && $tscid){
            $this->db->trans_begin();//开启事务
            $log_content =  $this->task_model->log_content();
            if ($status==1){
                $subtask = $this->db->query("select st.*, t.commission from tan_subtasks st left join tan_task t on t.tid=st.tid where st.sid=$tsid")->row_array();

                if ($subtask['is_gived']==0){
                    $account = $this->account_model->get($subtask['uid']);
                    $amount = $subtask['commission'];

                    $update_account = array(
                        'balance' => $account['balance'] + $amount,//账户余额
                        'total' => $account['total'] + $amount,//总额金额
                    );
                    $res3 = $this->account_model->update($update_account,$subtask['uid']);

                    //弹溜溜明细
                    $finance_list_data = array();
                    $finance_list_data['user_id'] = $subtask['uid'];
                    $finance_list_data['content'] = '任务佣金'.$amount.'溜溜币';
                    $finance_list_data['finance'] = $amount;
                    $finance_list_data['finance_balance'] = $update_account['balance'];
                    $finance_list_data['reward_type'] = 'spread_award';
                    $finance_list_data['type'] = 1;//收入
                    $finance_list_data['create_time'] = time();
                    $finance_list_data['month'] = date("Ym");
                    $finance_list_data['day'] = date("Ymd");

                    $res4 = $this->finance_list_model->insert($finance_list_data);
                }else{
                    $res3 = $res4 = true;
                }

                $subdata['status'] = 1;
                $subdata['is_end'] = 1;
                $subdata['is_gived'] = 1;
                $res1 = $this->db->where(array('sid'=>$tsid))->update('tan_subtasks',$subdata);
                $appdata['status'] = 2;
                $appdata['check_time'] = time();
                $res2 = $this->db->where(array('cid'=>$tscid))->update('tan_complaint',$appdata);
                $logarr_content = $log_content['appeal_pass'];
            }
            if ($status==2){
                $subdata['status'] = 2;
                $subdata['is_end'] = 0;
                $subdata['is_gived'] = 0;
                $res1 = $this->db->where(array('sid'=>$tsid))->update('tan_subtasks',$subdata);
                $appdata['status'] = 1;
                $appdata['check_time'] = time();
                $res2 = $this->db->where(array('cid'=>$tscid))->update('tan_complaint',$appdata);
                $res3 = $res4 = true;
                $logarr_content = $log_content['appeal_fail'];
            }

            if ($res1 && $res2 && $res3 && $res4){
                $this->db->trans_commit();//提交事务
                $result = array(
                    "reqStatus" => true,
                    "meg"   => "提交成功",
                );

                $log_arr = array(
                    'type_id'=>$tsid,
                    'uid'=>$this->user_info['user_id'],
                    'type' => 2,
                    'content'=>$logarr_content,
                    'add_time'=>time(),
                );
                $this->task_model->add_subtasks_log($log_arr);
            }else{
                $this->db->trans_rollback();//事务回滚
                $result = array(
                    "reqStatus" => false,
                    "meg"   => "提交失败，请稍候重试",
                );
            }
        }
        echo json_encode($result,JSON_HEX_TAG);die;
    }

    //暂停任务
    function ajax_task_pause(){
        $tid =  decrypt_wenda_id($_REQUEST['tid']);
        $uid = $this->userinfo['user_id'];
        $status = empty($_REQUEST['status'])?0:1;
        //检查是不是自己发布的任务
        $task = $this->db->query("select * from tan_task where tid={$tid} and uid={$uid}")->row_array();
        if(empty($task)){
            $result = array(
                "reqStatus" => false,
                "meg"   => "请求失败",
            );
        }else{
            $this->db->query("update tan_task set is_pause={$status} where tid={$tid}");
            $result = array(
                "reqStatus" => true,
                "meg"   => "操作成功",
            );
        }
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    //取消申诉
    function ajax_cancelappeal(){
        $tsid = isset($_REQUEST['tsid']) ? trim($_REQUEST['tsid']) : 0;
        $tscid = isset($_REQUEST['tscid']) ? trim($_REQUEST['tscid']) : 0;
        $tsid = decrypt_wenda_id($tsid);
        $tscid = decrypt_wenda_id($tscid);
        if ($tsid && $tscid){
            $this->db->trans_begin();//开启事务
            $subdata['is_end'] = 2;
            $res1 = $this->db->where(array('sid'=>$tsid))->update('tan_subtasks',$subdata);
            $appdata['status'] = 4;
            $res2 = $this->db->where(array('cid'=>$tscid))->update('tan_complaint',$appdata);

            if ($res1 && $res2){
                $this->db->trans_commit();//提交事务
                $result = array(
                    "reqStatus" => true,
                    "meg"   => "取消成功",
                );
                $log_content =  $this->task_model->log_content();
                $log_arr = array(
                    'type_id'=>$tsid,
                    'uid'=>$this->user_info['user_id'],
                    'type' => 2,
                    'content'=>$log_content['cancel_subtask'],
                    'add_time'=>time(),
                );
                $this->task_model->add_subtasks_log($log_arr);
            }else{
                $this->db->trans_rollback();//事务回滚
                $result = array(
                    "reqStatus" => false,
                    "meg"   => "取消失败，请稍候重试",
                );
            }
        }
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    //申请客服介入
    function ajax_taskkefu(){
        $tscid = isset($_REQUEST['tscid']) ? trim($_REQUEST['tscid']) : 0;
        $tscid = decrypt_wenda_id($tscid);
        //通过tscid获取sid

        if ($tscid){
            $this->db->trans_begin();//开启事务

            $appdata['is_kefu'] = 1;
            $res = $this->db->where(array('cid'=>$tscid))->update('tan_complaint',$appdata);
            $complaint = $this->db->query("select * from tan_complaint where cid={$tscid}")->row_array();
            $sid = $complaint['sid'];

            if ($res){
                $this->db->trans_commit();//提交事务
                $result = array(
                    "reqStatus" => true,
                    "meg"   => "申请成功",
                );
                $log_content =  $this->task_model->log_content();
                $log_arr = array(
                    'type_id'=>$sid,
                    'uid'=>$this->user_info['user_id'],
                    'type' => 2,
                    'content'=>$log_content['apply_service'],
                    'add_time'=>time(),
                );
                $this->task_model->add_subtasks_log($log_arr);
            }else{
                $this->db->trans_rollback();//事务回滚
                $result = array(
                    "reqStatus" => false,
                    "meg"   => "申请失败，请稍候重试",
                );
            }
        }
        echo json_encode($result,JSON_HEX_TAG);die;
    }
    //关闭任务
    function ajax_closetask(){
        $tid = isset($_REQUEST['tid']) ? trim($_REQUEST['tid']) : 0;

        if ($tid){
            $tid = decrypt_wenda_id($tid);
            $task_son = $this->db->query("select * from tan_subtasks where tid=$tid and is_end=0")->num_rows();
            if ($task_son>0){
                $result = array(
                    "reqStatus" => false,
                    "meg"   => "尚有任务未处理完成，不允许关闭",
                );
            }else{
                $this->db->trans_begin();//开启事务

                $task_info = $this->db->query("select * from tan_task where tid=$tid")->row_array();
                if ($task_info['is_end']==0 && $task_info['status']<>2 && $task_info['status']<>0){
                    if($task_info['cate_id'] == 1 || $task_info['cate_id'] == 2){
                        $sub_num = $this->db->query("select * from tan_subtasks where tid=$tid and is_end=1")->num_rows();
                        //总金额
                        $amount = $task_info['commission']*$task_info['sub_num']+$task_info['deposit']+$task_info['sponsorship_money'];
                        //已完成的金额
                        $succ_amount = ($task_info['commission'] * $sub_num)  + ($task_info['sponsorship_money']*($sub_num/$task_info['sub_num']));
                        $return_amount = $amount-$succ_amount;
                    }else if($task_info['cate_id'] == 3){
                        $amount = $task_info['investment_money_amount'] * 1.0*$task_info['commission_per'] /100;
                        $succ_info = $this->db->query("select sum(investment_money) as succ_num from tan_subtasks where tid=$tid and is_end=1")->row_array();
                        $succ_amount = empty($succ_info)?0:$succ_info['succ_num'];
                        $return_amount = ($amount-$succ_amount)*10000;
                    }

                    $account = $this->account_model->get($task_info['uid']);
                    $update_account = array(
                        'balance' => $account['balance'] + $return_amount,//账户余额
                        'expend' => $account['expend'] - $return_amount,//总额金额
                    );
                    $res1 = $this->account_model->update($update_account,$task_info['uid']);

                    //弹溜溜明细
                    $finance_list_data = array();
                    $finance_list_data['user_id'] = $task_info['uid'];
                    $finance_list_data['content'] = '任务：'.$task_info['title'].'，中途关闭，退回部分：'.$return_amount.'溜溜币';
                    $finance_list_data['finance'] = $return_amount;
                    $finance_list_data['finance_balance'] = $update_account['balance'];
                    $finance_list_data['reward_type'] = 'spread_award';
                    $finance_list_data['type'] = 1;//收入
                    $finance_list_data['create_time'] = time();
                    $finance_list_data['month'] = date("Ym");
                    $finance_list_data['day'] = date("Ymd");
                    $res2 = $this->finance_list_model->insert($finance_list_data);
                }else{
                    $res1 = $res2 = true;
                }

                $data['is_end'] = 1;
                $res = $this->db->where(array('tid'=>$tid))->update('task',$data);

                if ($res && $res1 && $res2){
                    $this->db->trans_commit();//提交事务
                    $result = array(
                        "reqStatus" => true,
                        "meg"   => "关闭成功",
                    );
                    //关闭任务记录log
                    $log_content =  $this->task_model->log_content();
                    $log_arr = array(
                        'type_id'=>$tid,
                        'uid'=>$this->userinfo['user_id'],
                        'type' => 1,
                        'content'=>$log_content['close_task'],
                        'add_time'=>time(),
                    );
                    $this->task_model->add_subtasks_log($log_arr);
                }else{
                    $this->db->trans_rollback();//事务回滚
                    $result = array(
                        "reqStatus" => false,
                        "meg"   => "关闭失败",
                    );
                }
            }

        }else{
            $result = array(
                "reqStatus" => false,
                "meg"   => "数据错误",
            );
        }
        echo json_encode($result,JSON_HEX_TAG);die;

    }
    //个人空间任务领取列表
    function ajax_room_taskrec(){
        if($_POST){
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $type = isset($_REQUEST['type']) ? trim($_REQUEST['type']) : 0;
            $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
            $uuid = decrypt_user_id($uuid);
            $records_per_page = 10;

            if($type == 1){//未提交
                $where = " and st.is_post = 0 ";
            }elseif($type == 2){//已提交
                $where = " and st.is_post = 1";
            }else{//全部
                $where = "and 1 = 1";
            }
            $web_config = $this->task_model->website_config();
            $totalCount = $this->db->query("select st.* from tan_subtasks st where st.uid = $uuid $where order by st.sid desc")->num_rows();
            $list = $this->db->query("select st.*,t.title,t.commission,t.commission_per,t.cate_id from tan_subtasks st left join tan_task t on t.tid=st.tid where st.uid = $uuid $where  order by st.sid desc limit ".($pageIndex * $records_per_page).",".$records_per_page)->result_array();
            $html = "";

            foreach ($list as $key => $val){
                $list[$key]['left_time'] = -1;
                $list[$key]['task_status'] = "";
                $list[$key]['rec_sta'] = "";
                $list[$key]['subtask_status'] = "";
                $list[$key]['end_num_html'] = "";
                $list[$key]['task_url'] = web_url("task/" . encrypt_wenda_id($val['tid']));
                if ($val['is_end'] == 1) {
                    $list[$key]['subtask_status'] = "<span class='green' style='font-size: 16px;height: 27px;overflow: hidden;'>成功</span>";
                }
                if ($val['is_end'] == 2) {
                    $list[$key]['subtask_status'] = "<span class='red' style='font-size: 16px;height: 27px;overflow: hidden;'>失败</span>";
                }
                if ($val['cate_id']==4){
                    if ($val['qualification']==1){
                        if ($val['apply_end']==1){
                            $list[$key]['task_status'] .= "&nbsp;<span class='green'>已申请结束</span>";
                            if ($val['is_end']==1){
                                $list[$key]['end_num_html'] .= "完成数量：".$val['end_num'];
                            }
                        }else {
                            $list[$key]['rec_sta'] .= "&nbsp;&nbsp;<a href='javascript:;' onclick='apply_finish(" . encrypt_wenda_id($val['tid']) . "," . encrypt_wenda_id($val['sid']) . ")'><span class='bj-red colfff' style='border-radius:3px;padding: 4px;'>申请结束</span></a>";
                            $list[$key]['task_status'] .= '&nbsp;<span class="green">资质通过</span>';
                        }
                    }elseif ($val['qualification']==2){
                        $list[$key]['task_status'] .= '&nbsp;<span class="red">资质未通过</span>';
                    }else{
                        $list[$key]['task_status'] .= '&nbsp;<span class="red">资质未验证</span>';
                    }
                }else {

                    if ($val['is_post'] == 1) {
                        $list[$key]['task_status'] .= "<span class='green'>已提交</span>&nbsp;";
                        if ($val['status'] == 4) {
                            $list[$key]['task_status'] .= "<span class='error'>已取消</span>&nbsp;";
                        } else if ($val['status'] == 2) {
                            //添加时间：配置有时间限制（60分钟），当前时间 - 审核时间
                            $task_promulgator_period = $web_config['task_promulgator_period'];//单位：小时
                            $time_dif = $task_promulgator_period * 3600 - (time() - $val['check_time']);
                            $left_time = $time_dif < 0 ? 0 : $time_dif;
                            $list[$key]['task_promulgator_period'] = $left_time;
                            $list[$key]['task_status'] .= "&nbsp;<span class='red'>未通过</span>";
                            $appeal_info = $this->db->query("select c.*,u.username as initiator from tan_complaint c left join tan_users u on u.user_id=c.uid where c.sid=" . $val['sid'])->row_array();
                            if ($appeal_info) {
                                $list[$key]['rec_sta'] .= "<a href='" . web_url("account/taskappeal") . "?sid=" . encrypt_wenda_id($val['sid']) . "'><span class='bj-red colfff' style='border-radius:3px;padding: 4px;'>申诉详情</span></a>";
                                switch ($appeal_info['status']) {
                                    case 0:
                                        $appeal_tx = "申诉中";
                                        break;
                                    case 1:
                                        $appeal_tx = "申诉未通过";
                                        break;
                                    case 2:
                                        $appeal_tx = "申诉成功";
                                        break;
                                    case 4:
                                        $appeal_tx = "取消申诉";
                                        break;
                                    case 5:
                                        $appeal_tx = "申诉失败";
                                        break;
                                    default:
                                        $appeal_tx = "";
                                        break;
                                }
                                $list[$key]['task_status'] .= "&nbsp;<span class='blue'>" . $appeal_tx . "</span>";
                            } else {
                                $list[$key]['task_status'] .= "&nbsp;<span class='red'>未申诉</span>";

                                if ($val['is_end'] != 2) {
                                    $list[$key]['rec_sta'] .= "<a href='" . web_url("account/taskappeal") . "?sid=" . encrypt_wenda_id($val['sid']) . "'><span class='bj-red colfff' style='border-radius:3px;padding: 4px;'>申&nbsp;&nbsp;诉</span></a>";
                                }
                            }


                        } elseif ($val['status'] == 1) {
                            $list[$key]['task_status'] .= "&nbsp;<span class='green'>已通过</span>";
                        } else {
                            $list[$key]['task_status'] .= "&nbsp;<span class='blue'>等待验证</span>";
                            $list[$key]['rec_sta'] .= "&nbsp;&nbsp;<a href='javascript:;' onclick='cancel_apply(" . encrypt_wenda_id($val['tid']) . ")'><span class='bj-red colfff' style='border-radius:3px;padding: 4px;'>取消任务</span></a>";
                            $list[$key]['rec_sta'] .= "&nbsp;&nbsp;<a href='" . web_url("task/" . encrypt_wenda_id($val['tid'])) . "'><span class='bj-red colfff' style='border-radius:3px;padding: 4px;'>修改认证</span></a>";
                        }

                    } elseif ($val['is_post'] == 0) {
                        if ($val['status'] == 4 && $val['is_end'] == 2) {
                            $list[$key]['task_status'] .= "<span class='error'>已取消</span>&nbsp;";
                        } elseif ($val['status'] == 3 && $val['is_end'] == 2) {
                            $list[$key]['task_status'] .= "<span class='error'>超时失败</span>&nbsp;";
                        } else {
                            //未提交加倒计时
                            $dead_time = (int)$web_config['task_fail_period'];
                            $time_dif = time() - $val['add_time'];
                            $left_time = ($dead_time * 3600 - $time_dif) < 0 ? 0 : $dead_time * 3600 - $time_dif;
                            //$left_time = (60*60 - $time_dif)<0 ? 0 :60*60 - $time_dif;
                            $list[$key]['left_time'] = $left_time;
                            $list[$key]['task_status'] .= "<span class='error'>未提交</span>&nbsp;";
                            $list[$key]['rec_sta'] .= "&nbsp;&nbsp;<a href='javascript:;' onclick='cancel_apply(" . encrypt_wenda_id($val['tid']) . ")'><span class='bj-red colfff' style='border-radius:3px;padding: 4px;'>取消任务</span></a>";
                            $list[$key]['rec_sta'] .= "&nbsp;&nbsp;<a href='" . web_url("task/" . encrypt_wenda_id($val['tid'])) . "' target='_blank' ><span class='bj-blue colfff' style='border-radius:3px;padding: 4px;'>提交认证</span></a>";
                        }
                    }

                    /* lht 2018/5/18 16:28 区间理财任务佣金 */
                    if ($val['cate_id'] == 3) {
                        $list[$key]['commission'] = round($val['commission_per'] * $val['investment_money']);
                    } else {
                        $list[$key]['commission'] = $val['commission'] / 10000;
                    }
                }

//                $html .= "<div class='con mt20 pb10'>
//
//                            <div class='right-info fl'>
//                                <a>$val[task_sn]</a>
//                                <div class='info mt10'>
//                                        任务名称：<a href='".web_url("task/".encrypt_wenda_id($val['tid']))."' target='_blank' >$val[title]</a>&nbsp;&nbsp;&nbsp;&nbsp;
//                                        佣金：$val[commission]&nbsp;&nbsp;&nbsp;&nbsp;
//                                        状态：$task_status&nbsp;&nbsp;&nbsp;&nbsp;
//                                        验证意见：$val[suggestion]
//                                </div>
//                            </div>
//                            <div class='fr' style=''>
//                                $rec_sta
//                            </div>
//                            <div class='clear'></div>
//                        </div>";
            }
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "htmlData" => $list,
                    "goto" => true
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }
    //任务申诉
    function ajax_appealsub(){
        $tsid = isset($_REQUEST['tsid']) ? trim($_REQUEST['tsid']) : 0;
        $tsid = decrypt_wenda_id($tsid);
        $data['content_word'] = isset($_REQUEST['content_word']) ? trim($_REQUEST['content_word']) : '';

        $subtask_info =  $this->db->query("select * from tan_subtasks where sid=$tsid")->row_array();
        $appeal_info = $this->db->query("select c.*,u.username as initiator from tan_complaint c left join tan_users u on u.user_id=c.uid where c.sid=$tsid")->row_array();
        $this->db->trans_begin();

        if (!$appeal_info){
            $appeal_data['sid'] = $tsid;
            $appeal_data['uid'] = $subtask_info['uid'];
            $appeal_data['add_time'] = time();
            $appeal_data['com_sn'] = 'C'.date('YmdHis').rand(1000,9999);
            $this->db->insert('tan_complaint', $appeal_data);
            $appeal_id = $this->db->insert_id();
            //第一次申请
        }else{
            $appeal_id = $appeal_info['cid'];
        }
        $appeal_comm = $this->db->query("select * from tan_complaint_comm where uid=".$this->userinfo['user_id']." and cid=$appeal_id order by add_time desc limit 1")->row_array();
        if (time()-$appeal_comm['add_time']<10){
            $result = array(
                "reqStatus" => false,
                "meg"   => "您说话太快！请稍候",
            );
        }else{
            $data['cid'] = $appeal_id;
            $data['uid'] = $this->userinfo['user_id'];
            $data['add_time'] = time();

            $this->db->insert('tan_complaint_comm', $data);
            $res = $this->db->insert_id();

            if ($res){
                $this->db->trans_commit();
                $result = array(
                    "reqStatus" => true,
                    "meg"   => "提交成功",
                );
            }else{
                $this->db->trans_rollback();
                $result = array(
                    "reqStatus" => false,
                    "meg"   => "提交失败",
                );
            }
        }



        echo json_encode($result,JSON_HEX_TAG);die;

    }
    //举报
    function ajax_report(){
        $this->is_login();
        if($_POST){
            $type = isset($_POST['type']) ? trim($_POST['type']) : "其他";
            $content = isset($_POST['des']) ? trim($_POST['des']) : "";
            $rel = isset($_POST['rel']) ? trim($_POST['rel']) : "";
            
            $data = array();
            $data['target_type'] = $type;
            $data['target_content'] = $content;
            $data['target_rel'] = $rel;
            $data['create_time'] = time();
            $this->db->insert("bbs_report_list",$data);
            
            $mess['reqStatus'] = true;
            $mess['errorMsg'] = "举报成功！";
            echo JSON($mess);exit;
            
        }
    }
    function check_login(){
        if($this->bbs_userinfo){
            $mess['reqStatus'] = true;
        }else{
            $mess['reqStatus'] = false;
        }
        echo JSON($mess);exit;
    }
    function ajax_modify_nickname(){
        $this->is_login();
        if($_POST){
            $nick_name = isset($_POST['nickName']) ? trim($_POST['nickName']) : "";
            if(!$nick_name){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1001;
                $mess['errorMsg'] = "昵称长度不符合要求";
                echo JSON($mess);exit;
            }
            
            $no_allow = array("弹溜溜客服","弹溜溜官方","弹溜溜机器人","官方客服","弹溜溜","溜溜客服","溜溜官方","溜溜小秘书","弹溜溜小秘书","弹溜溜小秘书","一元夺宝","弹溜溜夺宝","溜溜夺宝");
            if(in_array($nick_name, $no_allow)){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1001;
                $mess['errorMsg'] = "禁用名称，请更换";
                echo JSON($mess);exit;
            }
            $result = $this->db->query("update tan_users_info set nickname = '$nick_name' where user_id = ".$this->bbs_userinfo['user_id']);
            if($result){
                
                $this->users_model->users_alter($this->bbs_userinfo['user_id'],"isupdate");
                
                $mess['reqStatus'] = true;
                $mess['errorMsg'] = "";
                echo JSON($mess);exit;
            }else{
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);exit;
            }
        }
    }
    function ajax_modify_signature(){
        $this->is_login();
        if($_POST){
            $signature = isset($_POST['signature']) ? trim($_POST['signature']) : "";
            
            $result = $this->db->query("update tan_users_info set signature = '$signature' where user_id = ".$this->bbs_userinfo['user_id']);
            if($result){
                $this->users_model->users_alter($this->bbs_userinfo['user_id'],"isupdate");
                $mess['reqStatus'] = true;
                $mess['errorMsg'] = "";
                echo JSON($mess);exit;
            }else{
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);exit;
            }
        }
    }
    //标记全部已读
    function ajax_mark_reads(){
        $this->is_login();
        if($_POST){
            $type = isset($_POST['type']) ? trim($_POST['type']) : 0;
            $user_id = $this->bbs_userinfo['user_id'];
            $data = array();
            if ($type=="system"){
                $notice_results = $this->db->query("select id,is_read from tan_bbs_notice where recieve_id = '".$user_id."' and type = '".$type."' and is_read not like '%$user_id%'")->result_array();

                foreach($notice_results as $k=>$val){
                    $temp = array();
                    $temp['id'] = $val['id'];
                    $temp['is_read'] = $val['is_read'].",".$user_id;
                    $data[] = $temp;
                }
            }else{
                $notice_results = $this->db->query("select id from tan_bbs_notice where recieve_id = '".$user_id."' and type = '".$type."' and is_read = ''")->result_array();
                foreach($notice_results as $k=>$val){
                    $temp = array();
                    $temp['id'] = $val['id'];
                    $temp['is_read'] = ",".$user_id;
                    $data[] = $temp;
                }
            }
            if($data){
                $results = $this->db->update_batch('tan_bbs_notice', $data, 'id');
            }else{
                $results = 1;
            }


            if($results){
                $mess['reqStatus'] = true;
                echo JSON($mess);exit;
            }else{
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);exit;
            }
        }
    }
    
    //兑换溜珠
    function ajax_exchange(){
        if($_POST){
            $this->is_login();
            $exchangeNum = isset($_POST['exchangeNum']) ? trim($_POST['exchangeNum']) : 0;
            $exchangePass = isset($_POST['exchangePass']) ? trim($_POST['exchangePass']) : 0;
            if(!$exchangeNum){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "请输入有效的兑换个数";
                echo JSON($mess);exit;
            }
            if($exchangeNum < 10){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "兑换个数需≥10";
                echo JSON($mess);exit;
            }
            
            if(($exchangeNum * 10000) > $this->bbs_userinfo['account']['balance']){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "余额不足，无法兑换哦";
                echo JSON($mess);exit;
            }
            
            if(!$exchangePass){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "交易密码有误";
                echo JSON($mess);exit;
            }
            if($this->bbs_userinfo['paypassword'] != md5(md5($exchangePass) .$this->bbs_userinfo['salt'])){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "请输入正确的交易密码";
                echo JSON($mess);exit;
            }
            
            $this->db->trans_begin();//开启事务
            $account_data = array();
            $account_data['balance'] = $this->bbs_userinfo['account']['balance'] - ($exchangeNum * 10000);
            $account_data['expend'] = $this->bbs_userinfo['account']['expend'] + ($exchangeNum * 10000);
            $query1 = $this->db->where("user_id",$this->bbs_userinfo['user_id'])->update("account",$account_data);
            
            $bbs_account_data = array();
            $bbs_account_data['balance'] = $this->bbs_userinfo['balance'] + $exchangeNum;
            $bbs_account_data['total'] = $this->bbs_userinfo['total'] + $exchangeNum;
            $query2 = $this->db->where("user_id",$this->bbs_userinfo['user_id'])->update("bbs_account",$bbs_account_data);
            if($query1 && $query2){
                $this->db->trans_commit();//提交事务
                //溜溜币明细
                $finance_list_data = array();
                $finance_list_data['user_id'] = $this->bbs_userinfo['user_id'];
                $finance_list_data['content'] = "兑换".$exchangeNum."个溜珠";
                $finance_list_data['finance'] = ($exchangeNum * 10000);
                $finance_list_data['finance_balance'] = $account_data['balance'];
                $finance_list_data['reward_type'] = 'exchange_deduct';
                $finance_list_data['type'] = 2;//支出
                $finance_list_data['create_time'] = time();
                $finance_list_data['month'] = date("Ym");
                $finance_list_data['day'] = date("Ymd");
                $this->db->insert("finance_list",$finance_list_data);
                
                //溜珠明细
                $zhu_detail = array();
                $zhu_detail['user_id'] = $this->bbs_userinfo['user_id'];
                $zhu_detail['num'] = $exchangeNum;
                $zhu_detail['type'] = "溜溜币兑换";
                $zhu_detail['style'] = 1;
                $zhu_detail['create_time'] = time();
                $this->db->insert("bbs_zhu_detail",$zhu_detail);
                
                $log_data = array();
                $log_data['user_id'] = $this->bbs_userinfo['user_id'];
                $log_data['events'] = 'exchange';
                $log_data['content'] = '成功兑换'.$exchangeNum."个溜珠，消耗".($exchangeNum * 10000)."个溜溜币";
                $log_data['ip'] = $this->input->ip_address();
                $log_data['create_time'] = time();
                $this->db->insert("users_log",$log_data);
                
                $mess['reqStatus'] = true;
                $mess['errorMsg'] = "成功兑换，溜珠余额：".$bbs_account_data['balance'];
                echo JSON($mess);exit;
                
            }else{
                $this->db->trans_rollback();//事务回滚
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);exit;
            }
        }
    }
    //视频点赞or点差
    function video_like_num_add(){
        $this->is_login();
        if($_POST){
            $video_id = isset($_POST['video_id']) ? trim($_POST['video_id']) : 0;
            $status = trim($_POST['status']);
            $type = isset($_POST['type']) ? trim($_POST['type']) : "like";
            $video_id = decrypt_video_id($video_id);
            $video = $this->db->select("id,title,likes,hates")->from("video")->where(array("id"=>$video_id,'status'=>1))->order_by("id desc")->get()->row_array();
            if(!$video){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "视频资源不存在或已被删除";
                echo JSON($mess);exit;
            }
            $user_id = $this->bbs_userinfo['user_id'];
            
            $data = array();
            $data['video_id'] = $video['id'];
            $data['user_id'] = $user_id;
            $data['create_time'] = time();
            if($type == "hate"){//讨厌操作
                $data['status'] = 0;
                $this->video_model->insert_video_hates($data);
                $mess['num'] = $video['hates'] + 1;
            }else{//喜欢操作
                $data['status'] = 1;
                $this->video_model->insert_video_like($data);
                $mess['num'] = $video['likes'] + 1;
            }
            
            $mess['reqStatus'] = true;
            $mess['type'] = $type;
            echo JSON($mess);exit;
            

            //发送消息
            /*$this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$article['authorid'],"operator_id"=>$article_id,"event_type"=>"event_like_article","is_show"=>1,"type"=>"article"));*/

//            $behavior = $this->bbs_account_model->check_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$article_id,"event_type"=>"event_like_article"));
//            if($behavior==null){
//            //更新个人动态
//            $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$article_id,"event_type"=>"event_like_article","is_show"=>1));
//            }

/*            $errmes['reqStatus'] = true;
            echo JSON($errmes);exit;*/
        }
    }

    //添加视频评论
    function comment_video_add(){
        $this->is_login();
        if($_POST){
            $video_id = isset($_REQUEST['vid']) ? trim($_REQUEST['vid']) : 0;//视频id
            $content = isset($_REQUEST['content']) ? trim($_REQUEST['content']) : "";//评论内容
            $comment_id = isset($_REQUEST['comment_id']) ? trim($_REQUEST['comment_id']) : 0;//回复的评论id
            $comment_uid = isset($_REQUEST['comment_uid']) ? trim($_REQUEST['comment_uid']) : 0;//回复的评论者
            $card_index = isset($_REQUEST['card']) ? trim($_REQUEST['card']) : 0;//回复的卡通图片
            $comment_id = $comment_id ? decrypt_comment_id($comment_id) : 0;
            $comment_uid = $comment_uid ? decrypt_user_id($comment_uid) : 0;
            $video_id = decrypt_video_id($video_id);
            //获取视频
            $video = $this->db->select("id,authorid,status,salt")->from("video")->where(array("id"=>$video_id))->order_by("create_time desc")->get()->row_array();
            
            if(!$video){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "视频不存在或已被删除，无法评论哦";
                echo JSON($mess);exit;
            }
            //获取评论
            if($comment_id){
                $comment = $this->db->select("id,uid,content")->from("video_comment")->where(array("id"=>$comment_id,"is_show"=>1))->order_by("create_time desc")->get()->row_array();
                if(!$comment){
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "此评论不存在或已删除，无法回复哦";
                    echo JSON($mess);exit;
                }
                if($comment['uid'] != $comment_uid){
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "非法操作".$comment['uid'];
                    echo JSON($mess);exit;
                }
            }

            if(strip_tags(trim($content)) == ""){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "回复内容不能为空！";
                echo JSON($mess);exit;
            }
            //如果评论的是视频作者本人
            $is_self = $video['authorid'] == $this->bbs_userinfo['user_id'];

            $data = array();
            $data["uid"] = $this->bbs_userinfo['user_id'];
            $data["video_id"] = $video['id'];
            $data["authorid"] = $video['authorid'];
            $data["content"] = strip_tags($content);
            $data["create_time"] = time();
            $data["month"] = date("Ym");
            $data["day"] = date("Ymd");
            $data["repay_user_id"] = $comment_uid ? $comment_uid : 0;
            $data["cid"] = $comment_id ? $comment_id : 0;
            $data["type"] = $comment_id ? 1 : 0;
            $data["card_index"] = $card_index;

            $this->db->trans_begin();
            $this->db->insert("video_comment",$data);
            $insert_id = $this->db->insert_id();
            $query2 = $this->db->query("update tan_video set commentnum = commentnum + 1 where id = ".$video['id']);
            
            if($insert_id && $query2){
                $this->db->trans_commit();

               /* //发送消息通知
                if($comment_id){
                    //回复评论
                    $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$comment_uid,"operator_id"=>$insert_id,"event_type"=>"event_comment_article","type"=>"article","is_show"=>1));
                }else{
                    //评论视频
                    if(!$is_self){
                        $this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$author_id,"operator_id"=>$insert_id,"event_type"=>"event_reply_article","type"=>"article","is_show"=>1));
                    }
                }*/

//                //更新个人动态
//                $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$result,"event_type"=>"event_comment_article","is_show"=>1));
                $mess['reqStatus'] = true;
                $mess['comment_url'] = web_url('video/'.$video['salt']."/comments/".encrypt_comment_id($insert_id));
                echo JSON($mess);exit;
                
            }else{
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);exit;
            }
        }
    }

    //添加、取消视频收藏
    function video_favor_act(){
        $this->is_login();
        if($_POST){
            $video_id = isset($_POST['collectId']) ? trim($_POST['collectId']) : 0;
            $is_favor = isset($_POST['is_favor']) ? trim($_POST['is_favor']) : 0;
            $video_id = decrypt_video_id($video_id);
            $video = $this->db->select("id,title,authorid")->from("video")->where(array("id"=>$video_id,"status"=>1))->get()->row_array();
            if(!$video){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "视频不存在或已被删除";
                echo JSON($mess);exit;
            }
            if($is_favor){//添加
                $status = $this->db->select("*")->from("video_favorite")->where(array("user_id"=>$this->bbs_userinfo['user_id'],"video_id"=>$video['id'],"is_del"=>0))->order_by("create_time desc")->get()->row_array();
                if($status){
                    $this->db->trans_begin();
                    $query1 = $this->db->query("update tan_video_favorite set is_del = 1 where user_id = ".$this->bbs_userinfo['user_id']." and video_id = ".$video['id']);
                    $query2 = $this->db->query("update tan_video set favornum = favornum + 1 where id = ".$video['id']);

                    if($query1 && $query2){
                        $this->db->trans_commit();
                        $mess['reqStatus'] = true;
                        echo JSON($mess);exit;
                    }else{
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);exit;
                    }
                }else{
                    $data = array();
                    $data['video_id'] = $video['id'];
                    $data['user_id'] = $this->bbs_userinfo['user_id'];
                    $data['author_id'] = $video['authorid'];
                    $data['is_del'] = 1;
                    $data['create_time'] = time();
                    
                    $this->db->trans_begin();
                    $this->db->insert("video_favorite",$data);
                    $query1 = $this->db->affected_rows();
                    $query2 = $this->db->query("update tan_video set favornum = favornum + 1 where id = ".$video['id']);
                    if($query1 && $query2){
                        $this->db->trans_commit();
                        //发送消息
                        //$this->insert_notice(array("user_id"=>$this->bbs_userinfo['user_id'],"recieve_id"=>$video['authorid'],"operator_id"=>$video['id'],"event_type"=>"event_collect_article","type"=>"article","is_show"=>1));

                        $mess['reqStatus'] = true;
                        echo JSON($mess);exit;
                    }else{
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);exit;
                    }
                }
//                $behavior = $this->bbs_account_model->check_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$author_id,"event_type"=>"event_collect_article"));
//                if($behavior==null){
//                    //更新个人动态
//                    $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$author_id,"event_type"=>"event_collect_article","is_show"=>1));
//                }

            }else{//取消操作

                $status = $this->db->select("*")->from("video_favorite")->where(array("user_id"=>$this->bbs_userinfo['user_id'],"video_id"=>$video['id']))->order_by("create_time desc")->get()->row_array();
                if(!$status){
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);exit;
                }
                $this->db->trans_begin();
                $query1 = $this->db->query("update tan_video_favorite set is_del = 0 where user_id = ".$this->bbs_userinfo['user_id']." and video_id = ".$video['id']);
                $query2 = $this->db->query("update tan_video set favornum = favornum - 1 where id = ".$video['id']);

                if($query1 && $query2){
                    $this->db->trans_commit();
                    $mess['reqStatus'] = true;
                    echo JSON($mess);exit;
                }else{
                    $this->db->trans_rollback();
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);exit;
                }
            }
        }
    }
    //增加视频阅读数
    function video_read_num_add(){
        if($_GET){
            $video_id = isset($_GET['vid']) ? trim($_GET['vid']) : 0;
            $video_id = decrypt_video_id($video_id);
            $video = $this->db->select("id,readnum")->from("video")->where(array("id"=>$video_id))->get()->row_array();
            if(!$video){//视频不存在
                $mess['reqStatus'] = false;
                echo JSON($mess);exit;
            }
            $this->db->trans_begin();
            $query = $this->db->query("update tan_video set readnum = readnum + 1 where id = ".$video_id);
            if($query){
                $this->db->trans_commit();
                
                $mess['reqStatus'] = true;
                $mess['readNum'] = $video['readnum'] + 1;
                echo JSON($mess);exit;
            }else{
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                echo JSON($mess);exit;
            }
        }
        
    }
    
    //社区签到
    function ajax_sign(){
        if($_POST){
            $mark_award = $this->config_award['mark_award'];
            $mess = array();
            //奖励溜溜币
            $amount = $award_amount = rand($mark_award['min'],$mark_award['max']);
            
            //上一次签到时间
            $mark_time = $this->bbs_userinfo['mark_time'];
            
            //判断是否已经签到了
            if(date("Ymd",$mark_time) == date('Ymd')){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1000;
                echo JSON($mess);exit; 
            }
            
            //连续签到次数
            $mark_count = $this->bbs_userinfo['mark_count'];
            if(!$mark_time){//第一次签到
                $mark_time = time();
                $mark_count = 1;
            }elseif(date("Ymd",$mark_time) == date("Ymd",  strtotime("-1 day"))){//连续签到
                $mark_time = time();
                $mark_count = $mark_count + 1;
            }else{//非连续签到
                $mark_time = time();
                $mark_count = 1;
            }
            
            
            $msg_finance = "签到奖励".$amount."溜溜币";
            //获取账户信息
            $account = $this->account_model->get($this->bbs_userinfo['user_id']);
            $account_data = array();
            $account_data['total'] = $account['total']+ $amount;//账户总额
            $account_data['balance'] = $account['balance'] + $amount;//账户余额
            //更新账户
            $result = $this->account_model->update($account_data,$this->bbs_userinfo['user_id']);
            if($result){
                //更新用户签到信息
                $data = array();
                $data['mark_time'] = $mark_time;
                $data['mark_count'] = $mark_count;
//                $data['lucky_count'] = $this->bbs_userinfo['lucky_count'] + 1;
                $this->users_model->user_update($data,  $this->bbs_userinfo['user_id']);
                        
                //写入签到记录
                $sign_data = array();
                $sign_data["user_id"] = $this->bbs_userinfo['user_id'];
                $sign_data["amount"] = $award_amount;
                $sign_data["amount_vip"] = $vip_amount ? $vip_amount : 0;
                $sign_data["exper"] = 0;
                $sign_data["exper_vip"] = 0;
                $sign_data['year_time'] = date("Y");
                $sign_data["month_time"] = date("m");
                $sign_data["day_time"] =date("d");
                $sign_data['create_time'] = time();
                $this->users_model->insert_user_sign($sign_data);
                
                //写入溜溜币明细
                $finance_list_data = array();
                $finance_list_data['user_id'] = $this->bbs_userinfo['user_id'];
                $finance_list_data['content'] = $msg_finance;
                $finance_list_data['finance'] = $amount;
                $finance_list_data['finance_balance'] = $account_data['balance'];
                $finance_list_data['reward_type'] = 'sign_award';
                $finance_list_data['type'] = 1;
                $finance_list_data['create_time'] = time();
                $finance_list_data['month'] = date("Ym");
                $finance_list_data['day'] = date("Ymd");
                $this->finance_list_model->insert($finance_list_data);
                
                //日志
                $log_data = array();
                $log_data['user_id'] = $this->bbs_userinfo['user_id'];
                $log_data['events'] = 'sign';
                $log_data['content'] = '签到成功';
                $log_data['ip'] = $this->input->ip_address();
                $log_data['create_time'] = time();
                $this->users_model->insert_log($log_data);
                
                $mess['status'] = '0';
                $mess['coin'] = $award_amount;
                $mess['expe'] = 0;
                $mess['mark_count'] = $mark_count;
                $mess['reqStatus'] = true;
                echo JSON($mess);exit;
            }
        }
    }
    //判断是否登录
    private function is_login(){
        if($_POST && !$this->bbs_userinfo){
            $mess['reqStatus'] = false;
            $mess['errorCode'] = 1001;
            $mess['errorMsg'] = "请先登录，再操作哦";
            echo JSON($mess);exit;
        }
        if($_GET && !$this->bbs_userinfo){
           redirect("/");
        }
    }
    //设置文章评论字符串
    private function set_comment_str($list,$start_index){
        $html = "";
        foreach ($list as $key => $val){
            $start_index = ($key + 1);
            
            $bbs_account = $this->db->query("select is_lottery,is_plat from tan_bbs_account where user_id = $val[uid]")->row_array();
            
            $is_self = $this->bbs_userinfo['user_id'] == $val['uid'];
            $str = "";
            //获取引用的评论
            $patent_comment = $val['cid'] ? $this->db->select("content,create_time")->from("bbs_article_comment")->where(array('id'=>$val['cid']))->order_by("id desc")->get()->row_array() : array();
            $uuid = encrypt_user_id($val['uid']);
            if(!$is_self){
                $str .= "<a href='javascript:void(0);' class='btn fr mr10' onclick=\"reply_comment_fn({comment_id:".encrypt_comment_id($val['id']).",commenter_name:'$val[comment_nickname]',commenter_uid:$uuid});\">回复</a>";
                $str .= "<a href='javascript:void(0);' class='report btn fr mr10 _report' data-rel='". web_url("p/".encrypt_article_id($val['article_id'])."/comments/".encrypt_comment_id($val['id']))."'>举报</a>";
            }else{
                $str .= "<a href='javascript:void(0);' class='del btn fr mr10' onclick='delete_comment_act({comment_id:".encrypt_comment_id($val['id']).",obj:this});'>删除</a>";
            }
            $yinyong = $patent_comment ? "<div class='quote'><p>引用 $val[reply_nickname] 发表于 ".date("Y-m-d H:i:s",$patent_comment['create_time'])." 的回复：</p><p>".str_replace("\n", "<br/>", $patent_comment[content])."</p></div>" : "";
            $html .= "<div class='reply-man reply-item'>
                <div class='head' id='comment-".encrypt_comment_id($val['id'])."' data-cid='".encrypt_comment_id($val['id'])."'>
                    <div class='header'>
                        <a href='".web_url("u/".$uuid)."' class='fl overhide'><img src='$val[comment_head_img]'/></a>
                    </div>
                    <div class='user fl'><a href='".web_url("u/".$uuid)."' class='name'>$val[comment_nickname]</a></div>
                    <div class='floor fr mr10'><span>".$start_index."F</span></div>
                    <div class='smallIcon fr overhide'>
                        <a href='".  finance_base_url("card")."' target='_blank' class='icon-index icon-small-experience1' title='溜溜卡'></a>
                        <a href='".  finance_base_url("mplat")."' target='_blank' class='icon-index icon-small-experience2".($bbs_account['is_plat'] ? "-1" : "")."' title='弹一弹'></a>
                        <a href='".  finance_base_url("mfunds")."' target='_blank' class='icon-index icon-small-experience3' title='溜溜筹'></a>
                        <a href='".  web_url("lottery")."' target='_blank' class='icon-index icon-small-experience4".($bbs_account['is_lottery'] ? "-1" : "")."' title='溜溜心愿'></a>
                    </div>
                </div>
                <div class='reply-con overhide'>
                    <div class='txt fl'>".$yinyong."
                        <div class='word'>
                            <p class='_T_reply_content'>".str_replace("\n", "<br/>", $val[content])."</p>
                        </div>
                    </div>
                    <div class='card fr mr10 ".($val['card_index'] ? "card".$val['card_index'] : "")."'></div>
                </div>
                <div class='bot overhide'>
                    <div class='time fl'>".date("Y-m-d H:i:s",$val['create_time'])."</div>
                    <div class='option'>".$str."</div>
                </div>
            </div>";
        }
        
        return $html;
    }
    
    //设置问答列表字符串
    private function set_wenda_str($type,$value,$list){
        if(!$list){return "";}
        $html = "";
        foreach ($list as $key =>$val){
            $share_url = share_url("wenda/".encrypt_wenda_id($val['id']));
            if($type == "hot" || $type='all'){//热门问答
                if($val['answer_id']){//答案已被采纳
                    $answer = $this->db->select("a.id,a.user_id,a.thumb,a.content,u.nickname,u.head_img")->from("bbs_wenda_answer a")->join("users_info u","u.user_id = a.user_id","left")->where(array("a.id"=>$val['answer_id'],"a.user_id"=>$val['answer_uid']))->order_by("a.id desc")->get()->row_array();
                }else{//答案未被采纳
                    $answer =  $this->db->select("a.id,a.user_id,a.likes,a.thumb,a.content,u.nickname,u.head_img")->from("bbs_wenda_answer a")->join("users_info u","u.user_id = a.user_id","left")->where(array("a.wenda_id"=>$val['id']))->order_by("a.likes desc")->get()->row_array();
                }
                $time_str = date("Y-m-d H:i",$val['create_time']);
            }elseif($type == "lasest"){//最新问答
                $answer = array();
                if($val['answernum']){
                    if($val['answer_id']){
                        $answer = $this->db->select("a.id,a.user_id,a.thumb,a.content,u.nickname,u.head_img")->from("bbs_wenda_answer a")->join("users_info u","u.user_id = a.user_id","left")->where(array("a.id"=>$val['answer_id'],"a.user_id"=>$val['answer_uid']))->order_by("a.id desc")->get()->row_array();
                    }else{
                        $answer =  $this->db->select("a.id,a.user_id,a.thumb,a.content,u.nickname,u.head_img")->from("bbs_wenda_answer a")->join("users_info u","u.user_id = a.user_id","left")->where(array("a.wenda_id"=>$val['id']))->order_by("a.likes desc,a.id desc")->get()->row_array();
                    }
                }
                
                $time_str = $this->set_time($val['create_time']);
            }else{//等待回答
                $answer = array();
                $time_str = $this->set_time($val['create_time']);
            }
            
            $tags_str = "";
            if($val['tags_name']){
                $tags_arr = explode(",", $val['tags_name']);
                foreach ($tags_arr as $v){
                    $v = explode("_", $v);
                    $tags_str .= "<a href='".web_url("wenda/tag-".$v[1])."' ".($value == $v[1] ? "class='on'" : "").">$v[0]</a>";
                }
            }
            
            $html .= "<li class='wd-problem'>";
            $html .= "  <div class='wen'>";
            $html .= "      <div class='label'>";
            $html .= "          <span class='".($answer ? "head" : "head2")."'><a href='".web_url("u/".encrypt_user_id($val['questioner_id']))."' target='_blank'><img src='$val[wd_headimg]'/></a></span>";
            $html .= "          <span class='icon-index icon-wen'></span>";
            $html .= "      </div>";
            $html .= "      <div class='title'><a href='".web_url("wenda/".encrypt_wenda_id($val['id']))."' target='_blank'>$val[title]</a></div>";
            $html .= "  </div>";
            $html .= "  <div class='da'>";
            if($answer){
                $html .= "  <div class='label'>";
                $html .= "      <a href='".web_url("u/".encrypt_user_id($answer['user_id']))."' target='_blank' class='head'><img src='$answer[head_img]'/></a>";
                $html .= "      <span class='icon-index icon-da'></span>";
                $html .= "  </div>";
            }
            $html .= "      <div class='user'>";
            if($answer){
                $html .= "      <a href='".web_url("u/".encrypt_user_id($answer['user_id']))."' target='_blank' class='name mr5 mb5'>$answer[nickname]</a>";
                $html .= "      <div class='usertitle ".($answer['thumb'] ? "mt5" : "")."'></div>";
                $html .= "      <a href='".web_url("wenda/".encrypt_wenda_id($val['id']))."' target='_blank' class='desc p10'>";
                if($answer['thumb']){
                    $html .= "      <img src='$answer[thumb]'/>";
                }
                $html .= "          <p class='textnum160 ".($answer[thumb] ? "w600" : "")."'>".($val['answer_id'] ? "最佳回答：" : "").strip_tags(trim($answer['content']))."</p>";
                $html .= "       </a>";
            }else{
                $html .= "      <a href='".web_url("wenda/".encrypt_wenda_id($val['id']))."' target='_blank' class='desc p10'>";
                $html .= "          <p>".trim($val['summary'])."</p>";
                $html .= "      </a>";
            }
            $html .= "          <div class='tags clear'>$tags_str</div>";
            $html .= "      </div>";
            $html .= "  </div>";
            $html .= "  <div class='info mt10 show-report'>";
            $html .= "      <ul class='fr'>";
            $html .= "          <li><span class='time'>$time_str</span></li>";
            $html .= "          <li>赞($val[likes])</li>";
            $html .= "          <li>关注($val[focusnum])</li>";
            $html .= "          <li>回答($val[answernum])</li>";
            $html .= "          <li>浏览($val[readnum])</li>";
            $html .= "      </ul>";
            $html .= "      <a href='javascript:void(0);' class='share fl mt5 pr10'><b class='icon-com icon-ask-share'></b>分享</a>";
            $html .= "      <a href='javascript:void(0);' class='report fl mt5 _report' data-rel='".web_url("wenda/".encrypt_wenda_id($val['id']))."'>|&nbsp;&nbsp;&nbsp;举报</a>";
            $html .= "      <div class='share-pop share'>";
            $html .= "          <a class='sina icon-tab icon-share-sina' title='分享到新浪微博' data-key='wb' data-title='#弹溜溜问答专栏--《$val[title]》--邀您一起回答#' data-content='$val[likes]人【喜欢】' data-ref='$share_url'></a>";
            $html .= "          <a class='qzone icon-tab icon-share-qzone' title='分享到QQ空间' data-key='qq' data-title='#弹溜溜问答专栏--《$val[title]》--邀您一起回答#' data-content='$val[likes]人【喜欢】' data-ref='$share_url'></a>";
            $html .= "          <a class='sweixin icon-tab icon-share-wechat' title='分享到微信' data-key='wx' data-wx-qrcode='/trcode.html?text=".urlencode($share_url)."&size=150&level=H'></a>";
            $html .= "      </div>";
            $html .= "      <div class='clear'></div>";
            
            $html .= "  </div>";
            $html .= "</li>";
        }
        return $html;
    }
    //设置问答列表字符串
    private function set_exposure_str($type,$value,$list){
        if(!$list){return "";}
        $html = "";
        foreach ($list as $key =>$val){
            $share_url = share_url("exposure/".encrypt_wenda_id($val['id']));
            if($type == "hot" || $type='all'){//热门问答
                if($val['answer_id']){//答案已被采纳
                    $answer = $this->db->select("a.id,a.user_id,a.thumb,a.content,u.nickname,u.head_img")->from("bbs_exposure_answer a")->join("users_info u","u.user_id = a.user_id","left")->where(array("a.id"=>$val['answer_id'],"a.user_id"=>$val['answer_uid']))->order_by("a.id desc")->get()->row_array();
                }else{//答案未被采纳
                    $answer =  $this->db->select("a.id,a.user_id,a.likes,a.thumb,a.content,u.nickname,u.head_img")->from("bbs_exposure_answer a")->join("users_info u","u.user_id = a.user_id","left")->where(array("a.wenda_id"=>$val['id']))->order_by("a.likes desc")->get()->row_array();
                }
                $time_str = date("Y-m-d H:i",$val['create_time']);
            }elseif($type == "lasest"){//最新问答
                $answer = array();
                if($val['answernum']){
                    if($val['answer_id']){
                        $answer = $this->db->select("a.id,a.user_id,a.thumb,a.content,u.nickname,u.head_img")->from("bbs_exposure_answer a")->join("users_info u","u.user_id = a.user_id","left")->where(array("a.id"=>$val['answer_id'],"a.user_id"=>$val['answer_uid']))->order_by("a.id desc")->get()->row_array();
                    }else{
                        $answer =  $this->db->select("a.id,a.user_id,a.thumb,a.content,u.nickname,u.head_img")->from("bbs_exposure_answer a")->join("users_info u","u.user_id = a.user_id","left")->where(array("a.wenda_id"=>$val['id']))->order_by("a.likes desc,a.id desc")->get()->row_array();
                    }
                }

                $time_str = $this->set_time($val['create_time']);
            }else{//等待回答
                $answer = array();
                $time_str = $this->set_time($val['create_time']);
            }

            $tags_str = "";
            if($val['tags_name']){
                $tags_arr = explode(",", $val['tags_name']);
                foreach ($tags_arr as $v){
                    $v = explode("_", $v);
                    $tags_str .= "<a href='".web_url("exposure/tag-".$v[1])."' ".($value == $v[1] ? "class='on'" : "").">$v[0]</a>";
                }
            }

            $html .= "<li class='wd-problem'>";
            $html .= "  <div class='wen'>";
            $html .= "      <div class='label'>";
            $html .= "          <span class='".($answer ? "head" : "head2")."'><a href='".web_url("u/".encrypt_user_id($val['questioner_id']))."' target='_blank'><img src='$val[wd_headimg]'/></a></span>";

            $html .= "      </div>";
            $html .= "      <div class='title'><a href='".web_url("exposure/".encrypt_wenda_id($val['id']))."' target='_blank'>$val[title]</a></div>";
            $html .= "  </div>";
            $html .= "  <div class='da'>";
            if($answer){
                $html .= "  <div class='label'>";
//                $html .= "      <a href='".web_url("u/".encrypt_user_id($answer['user_id']))."' target='_blank' class='head'><img src='$answer[head_img]'/></a>";

                $html .= "  </div>";
            }
            $html .= "      <div class='user'>";
            if($answer){
                $html .= "      <a href='".web_url("u/".encrypt_user_id($answer['user_id']))."' target='_blank' class='name mr5 mb5'>$answer[nickname]</a>";
                $html .= "      <div class='usertitle ".($answer['thumb'] ? "mt5" : "")."'></div>";
                $html .= "      <a href='".web_url("exposure/".encrypt_wenda_id($val['id']))."' target='_blank' class='desc p10'>";
                if($answer['thumb']){
                    $html .= "      <img src='$answer[thumb]'/>";
                }
                $html .= "          <p class='textnum160 ".($answer[thumb] ? "w600" : "")."'>".($val['answer_id'] ? "最佳回答：" : "").strip_tags(trim($answer['content']))."</p>";
                $html .= "       </a>";
            }else{
                $html .= "      <a href='".web_url("exposure/".encrypt_wenda_id($val['id']))."' target='_blank' class='desc p10'>";
                $html .= "          <p>".trim($val['summary'])."</p>";
                $html .= "      </a>";
            }
            $html .= "          <div class='tags clear'>$tags_str</div>";
            $html .= "      </div>";
            $html .= "  </div>";
            $html .= "  <div class='info mt10 show-report'>";
            $html .= "      <ul class='fr'>";
            $html .= "          <li><span class='time'>$time_str</span></li>";
            $html .= "          <li>赞($val[likes])</li>";
            $html .= "          <li>关注($val[focusnum])</li>";
            $html .= "          <li>评论($val[answernum])</li>";
            $html .= "          <li>浏览($val[readnum])</li>";
            $html .= "      </ul>";
            $html .= "      <a href='javascript:void(0);' class='share fl mt5 pr10'><b class='icon-com icon-ask-share'></b>分享</a>";
            $html .= "      <a href='javascript:void(0);' class='report fl mt5 _report' data-rel='".web_url("exposure/".encrypt_wenda_id($val['id']))."'>|&nbsp;&nbsp;&nbsp;举报</a>";
            $html .= "      <div class='share-pop share'>";
            $html .= "          <a class='sina icon-tab icon-share-sina' title='分享到新浪微博' data-key='wb' data-title='#弹溜溜问答专栏--《$val[title]》--邀您一起回答#' data-content='$val[likes]人【喜欢】' data-ref='$share_url'></a>";
            $html .= "          <a class='qzone icon-tab icon-share-qzone' title='分享到QQ空间' data-key='qq' data-title='#弹溜溜问答专栏--《$val[title]》--邀您一起回答#' data-content='$val[likes]人【喜欢】' data-ref='$share_url'></a>";
            $html .= "          <a class='sweixin icon-tab icon-share-wechat' title='分享到微信' data-key='wx' data-wx-qrcode='/trcode.html?text=".urlencode($share_url)."&size=150&level=H'></a>";
            $html .= "      </div>";
            $html .= "      <div class='clear'></div>";

            $html .= "  </div>";
            $html .= "</li>";
        }
        return $html;
    }

    //设置视频评论字符串
    private function set_video_comment_str($video,$list,$start_index){
        $html = "";
        foreach ($list as $key => $val){
            $start_index = ($key + 1);
            
            $bbs_account = $this->db->query("select is_lottery,is_plat from tan_bbs_account where user_id = $val[uid]")->row_array();
            
            $is_self = $this->bbs_userinfo['user_id'] == $val['uid'];
            $str = "";
            //获取引用的评论
            $patent_comment = $val['cid'] ? $this->db->select("content,create_time")->from("video_comment")->where(array('id'=>$val['cid']))->order_by("id desc")->get()->row_array() : array();
            $uuid = encrypt_user_id($val['uid']);
            if(!$is_self){
                $str .= "<a href='javascript:void(0);' class='btn fr mr10' onclick=\"reply_comment_fn({comment_id:".encrypt_comment_id($val['id']).",commenter_name:'$val[comment_nickname]',commenter_uid:$uuid});\">回复</a>";
                $str .= "<a href='javascript:void(0);' class='report btn fr mr10 _report' data-rel='".  host_url().web_url("video/".$video['salt']."/comments/".encrypt_comment_id($val['id']))."'>举报</a>";
            }else{
                $str .= "<a href='javascript:void(0);' class='del btn fr mr10' onclick='delete_video_comment_act({comment_id:".encrypt_comment_id($val['id']).",obj:this});'>删除</a>";
            }
            $yinyong = $patent_comment ? "<div class='quote'><p>引用 $val[reply_nickname] 发表于 ".date("Y-m-d H:i:s",$patent_comment['create_time'])." 的回复：</p><p>".str_replace("\n", "<br/>", $patent_comment[content])."</p></div>" : "";
            $html .= "<div class='reply-man reply-item'>
                <div class='head' id='comment-".encrypt_comment_id($val['id'])."' data-cid='".encrypt_comment_id($val['id'])."'>
                    <div class='header'>
                        <a href='".web_url("u/".$uuid)."' class='fl overhide'><img src='$val[comment_head_img]'/></a>
                    </div>
                    <div class='user fl'><a href='".web_url("u/".$uuid)."' class='name'>$val[comment_nickname]</a></div>
                    <div class='floor fr mr10'><span>".$start_index."F</span></div>
                    <div class='smallIcon fr overhide'>
                        <a href='".  finance_base_url("card")."' target='_blank' class='icon-index icon-small-experience1' title='溜溜卡'></a>
                        <a href='".  finance_base_url("mplat")."' target='_blank' class='icon-index icon-small-experience2".($bbs_account['is_plat'] ? "-1" : "")."' title='弹一弹'></a>
                        <a href='".  finance_base_url("mfunds")."' target='_blank' class='icon-index icon-small-experience3' title='溜溜筹'></a>
                        <a href='".  web_url("lottery")."' target='_blank' class='icon-index icon-small-experience4".($bbs_account['is_lottery'] ? "-1" : "")."' title='溜溜夺宝'></a>
                    </div>
                </div>
                <div class='reply-con overhide'>
                    <div class='txt fl'>".$yinyong."
                        <div class='word'>
                            <p class='_T_reply_content'>".str_replace("\n", "<br/>", $val[content])."</p>
                        </div>
                    </div>
                    <div class='card fr mr10 ".($val['card_index'] ? "card".$val['card_index'] : "")."'></div>
                </div>
                <div class='bot overhide'>
                    <div class='time fl'>".date("Y-m-d H:i:s",$val['create_time'])."</div>
                    <div class='option'>".$str."</div>
                </div>
            </div>";
        }
        
        return $html;
    }
    private function set_task_str($type,$value,$list){
        if(!$list){return "";}
        $html = "";
        foreach ($list as $key =>$val){
            $share_url = share_url("wenda/".encrypt_wenda_id($val['id']));
            if($type == "hot" || $type='all'){//热门问答
                if($val['answer_id']){//答案已被采纳
                    $answer = $this->db->select("a.id,a.user_id,a.thumb,a.content,u.nickname,u.head_img")->from("bbs_wenda_answer a")->join("users_info u","u.user_id = a.user_id","left")->where(array("a.id"=>$val['answer_id'],"a.user_id"=>$val['answer_uid']))->order_by("a.id desc")->get()->row_array();
                }else{//答案未被采纳
                    $answer =  $this->db->select("a.id,a.user_id,a.likes,a.thumb,a.content,u.nickname,u.head_img")->from("bbs_wenda_answer a")->join("users_info u","u.user_id = a.user_id","left")->where(array("a.wenda_id"=>$val['id']))->order_by("a.likes desc")->get()->row_array();
                }
                $time_str = date("Y-m-d H:i",$val['create_time']);
            }elseif($type == "lasest"){//最新问答
                $answer = array();
                if($val['answernum']){
                    if($val['answer_id']){
                        $answer = $this->db->select("a.id,a.user_id,a.thumb,a.content,u.nickname,u.head_img")->from("bbs_wenda_answer a")->join("users_info u","u.user_id = a.user_id","left")->where(array("a.id"=>$val['answer_id'],"a.user_id"=>$val['answer_uid']))->order_by("a.id desc")->get()->row_array();
                    }else{
                        $answer =  $this->db->select("a.id,a.user_id,a.thumb,a.content,u.nickname,u.head_img")->from("bbs_wenda_answer a")->join("users_info u","u.user_id = a.user_id","left")->where(array("a.wenda_id"=>$val['id']))->order_by("a.likes desc,a.id desc")->get()->row_array();
                    }
                }

                $time_str = $this->set_time($val['create_time']);
            }else{//等待回答
                $answer = array();
                $time_str = $this->set_time($val['create_time']);
            }
            $time_str = $this->set_time($val['add_time']);
//            var_dump($val['subnum']);exit();
            $tags_str = "";
            if($val['tags_name']){
                $tags_arr = explode(",", $val['tags_name']);
                foreach ($tags_arr as $v){
                    $v = explode("_", $v);
                    $tags_str .= "<a href='".web_url("wenda/tag-".$v[1])."' ".($value == $v[1] ? "class='on'" : "").">$v[0]</a>";
                }
            }
            
            $html .= "<li class='wd-problem'>";
            $html .= "  <div class='wen'>";
            $html .= "      <div class='label'>";
            $html .= "          <span class='".($answer ? "head" : "head2")."'><a href='".web_url("u/".encrypt_user_id($val['questioner_id']))."' target='_blank'><img src='$val[head_img]'/></a></span>";
            $html .= "          <span class='icon-index icon-wen'></span>";
            $html .= "      </div>";
            $html .= "      <div class='title'><a href='".web_url("wenda/".encrypt_wenda_id($val['id']))."' target='_blank'>$val[title]</a></div>";
            $html .= "  </div>";
            $html .= "  <div class='da'>";
            if($answer){
                $html .= "  <div class='label'>";
                $html .= "      <a href='".web_url("u/".encrypt_user_id($answer['user_id']))."' target='_blank' class='head'><img src='$val[head_img]'/></a>";
                $html .= "      <span class='icon-index icon-da'></span>";
                $html .= "  </div>";
            }
            $html .= "      <div class='user'>";
            if($answer){
                $html .= "      <a href='".web_url("u/".encrypt_user_id($answer['user_id']))."' target='_blank' class='name mr5 mb5'>$val[nickname]</a>";
                $html .= "      <div class='usertitle ".($answer['thumb'] ? "mt5" : "")."'></div>";
                $html .= "      <a href='".web_url("wenda/".encrypt_wenda_id($val['id']))."' target='_blank' class='desc p10'>";
                if($answer['thumb']){
                    $html .= "      <img src='$answer[thumb]'/>";
                }
                $html .= "          <p class='textnum160 ".($answer[thumb] ? "w600" : "")."'>".($val['answer_id'] ? "最佳回答：" : "").strip_tags(trim($answer['content']))."</p>";
                $html .= "       </a>";
            }else{
                $html .= "      <a href='".web_url("wenda/".encrypt_wenda_id($val['id']))."' target='_blank' class='desc p10'>";
                $html .= "          <p>".trim($val['content'])."</p>";
                $html .= "      </a>";
            }
            $html .= "          <div class='tags clear'>$tags_str</div>";
            $html .= "      </div>";
            $html .= "  </div>";
            $html .= "  <div class='info mt10 show-report'>";
            $html .= "      <ul class='fr'>";
            $html .= "          <li><span class='time'>$time_str</span></li>";
            $html .= "          <li>总任务数量($val[sub_num])</li>";
            $html .= "          <li>已领取任务数量($val[snum])</li>";
//            $html .= "          <li>回答($val[answernum])</li>";
//            $html .= "          <li>浏览($val[readnum])</li>";
            $html .= "      </ul>";
            $html .= "      <a href='javascript:void(0);' class='share fl mt5 pr10'><b class='icon-com icon-ask-share'></b>分享</a>";
            $html .= "      <a href='javascript:void(0);' class='report fl mt5 _report' data-rel='".web_url("wenda/".encrypt_wenda_id($val['id']))."'>|&nbsp;&nbsp;&nbsp;举报</a>";
            $html .= "      <div class='share-pop share'>";
            $html .= "          <a class='sina icon-tab icon-share-sina' title='分享到新浪微博' data-key='wb' data-title='#弹溜溜问答专栏--《$val[title]》--邀您一起回答#' data-content='$val[likes]人【喜欢】' data-ref='$share_url'></a>";
            $html .= "          <a class='qzone icon-tab icon-share-qzone' title='分享到QQ空间' data-key='qq' data-title='#弹溜溜问答专栏--《$val[title]》--邀您一起回答#' data-content='$val[likes]人【喜欢】' data-ref='$share_url'></a>";
            $html .= "          <a class='sweixin icon-tab icon-share-wechat' title='分享到微信' data-key='wx' data-wx-qrcode='/trcode.html?text=".urlencode($share_url)."&size=150&level=H'></a>";
            $html .= "      </div>";
            $html .= "      <div class='clear'></div>";

            $html .= "  </div>";
            $html .= "</li>";
        }
        return $html;
    }
}
